Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
# Changelog

## 2026-10 — Soundness fixes

Each of these made a false property verify; each fix has a fixture under
`test/examples/` with true and false properties.

- **Invariants** may not read `msg.sender` or `msg.value` (rejected, as
`block.*` already was): an invariant holds between transactions, whoever
calls next, and one over the caller was established for one caller and
assumed for the next (`invariant_msg_sender.sol`, `invariant_msg_value.sol`).
- **`require(cond, f())`** keeps the effects of its message arguments, which
run before the condition is assumed (`require_message_effects.sol`).
- **Quantified variables** range over their declared type:
`exists i : uint8 :: i == k` is no longer proven for every `k`
(`quantifier_types.sol`).
- **Bitwise results** have the type of the operation (a signed result can be
negative); `~x` is exact (`bitwise_types.sol`).
- **Constant expressions** have the value solc computes, exactly:
`(7 / 2) * 2` is 7; `2.5 ether` and `1e18` are accepted
(`constant_expressions.sol`).
- **`unchecked`**: a signed `/` and a power of named constants wrap within
their type (`unchecked_wrapping.sol`).
- **Specifications** divide like the code: `/` rounds toward zero and `%`
takes the sign of the dividend (`spec_division.sol`).
- **Mapping and array `storage` parameters** are rejected: writes through
them were lost (`storage_param_mapping.sol`, `storage_param_array.sol`).
- **Halts**: a call of a function that may end the transaction (assembly
`return`/`stop`, `selfdestruct`) is rejected; the caller used to continue
after it (`halt_in_helper.sol`, `selfdestruct_in_helper.sol`).
- **Structs** are copied where Solidity copies them (into storage, from
storage or calldata into memory) instead of shared, and a memory struct
passed to a function has unknown fields afterwards (`struct_copies.sol`).
- **Storage references** read the storage they refer to when the read
runs, not its value when the reference was taken
(`storage_reference_reads.sol`).

## 2026-10 — Contract invariants

- `@custom:strata invariant` is honored in the NatSpec above `contract`, not
Expand Down
18 changes: 13 additions & 5 deletions LIMITATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ This is not practical for verifying existing contracts but works for new designs
| `msg.sender`, `msg.value` | Used as keys or in expressions | ✅ |
| `address(0)`, type conversions | Truncate as the EVM does (`uint8(x)`, `int8(u)`, `bytes4(h)` keeps the high bytes); widening keeps the value | ✅ |
| `type(uint256).max/min` | Compile-time constants | ✅ |
| Arithmetic | `+`, `-`, `*`, `/`, `%`; `unchecked` wraps; signed `/`, `%` round toward zero; constant `**` folded | ✅ (checked overflow is not modelled as a revert: properties relying on it may not be proven) |
| Arithmetic | `+`, `-`, `*`, `/`, `%`; `unchecked` wraps; signed `/`, `%` round toward zero, in specifications too; constant expressions have solc's exact value; constant `**` folded; bitwise results stay in their type | ✅ (checked overflow is not modelled as a revert: properties relying on it may not be proven) |
| Unary operators in specs | `!paused`, negative literals (`-887272`) | ✅ |
| Named constants in specs | `requires status == NOT_ENTERED`, `modifies roles[DEFAULT_ADMIN_ROLE]` | ✅ |
| Subdenominations | `1 ether`, `2 days` folded to base units | ✅ |
Expand All @@ -94,6 +94,7 @@ This is not practical for verifying existing contracts but works for new designs
| `invariant` | Contract-level invariants checked on all functions | ✅ |
| `modifies` | Field-level and key-scoped frame conditions | ✅ |
| Modifiers | Inlined into each function using them, with arguments; `return` in the body still runs the code after `_` | ✅ (not modifiers of an imported base contract, which are reported) |
| Struct assignments | Copied into storage, and from storage or calldata into memory (assignments, declarations, arguments, returned values); memory-to-memory assignments share the struct, and a function a memory struct is passed to may change its fields | ✅ (a function writing a struct that is not a copy it made reports a spurious `heap frame` failure) |

## Not Yet Supported

Expand All @@ -102,11 +103,11 @@ This is not practical for verifying existing contracts but works for new designs
| Struct fields through mappings | ❌ Blocked (Core) | See above |
| `old()` in loop invariants | ❌ Blocked (Core) | `__old` marker not resolved in loop context |
| `@custom:strata lemma` | ❌ Not started | Needs Laurel grammar extension |
| `block.*`, `tx.*`, `msg.sig` | ✅ Modelled | Fixed for the transaction (two reads agree) and of their Solidity type; `block.timestamp` and `block.number` are positive. Not allowed in invariants: they change between transactions |
| `block.*`, `tx.*`, `msg.sig` | ✅ Modelled | Fixed for the transaction (two reads agree) and of their Solidity type; `block.timestamp` and `block.number` are positive. Not allowed in invariants, nor are `msg.sender` and `msg.value`: they change between transactions |
| `gasleft()`, balances, `send` | ⚠️ Unknown | A fresh value of the result type at every read or call |
| `msg.sender` in constructor | ❌ | Constructor handling incomplete |
| External calls / reentrancy | ⚠️ Havoc | A call of another contract (through an interface, `this.f()`, an external function value), a low-level `call`, or `new C(…)` may call back into the contract: its state is unknown after the call, except for the contract invariants, which an external function checks before the call and assumes after it. `view` calls and `staticcall` change nothing; nor do `send` and `transfer` (too little gas to). `delegatecall` may change all state, invariants included. Results are unknown values of their type. Constructors cannot be re-entered. `--assume-no-reentrancy` trusts that no call re-enters: calls (other than `delegatecall`) then change nothing |
| Assembly / inline Yul | ⚠️ Havoc | Not interpreted. Afterwards, unknown: the Solidity variables a block assigns; every memory variable if it writes memory; all contract state (of its type) if it may write storage (`sstore`, calls). A block that may `return` or `stop` ends the function on some paths. Rejected: assigning a storage reference, writing memory with a memory struct in scope, ending a constructor |
| Assembly / inline Yul | ⚠️ Havoc | Not interpreted. Afterwards, unknown: the Solidity variables a block assigns; every memory variable if it writes memory; all contract state (of its type) if it may write storage (`sstore`, calls). A block that may `return` or `stop` ends the transaction on some paths, as `selfdestruct` does. Rejected: assigning a storage reference, writing memory with a memory struct in scope, ending a constructor, and calling a function that may end the transaction (the code after the call would be verified as if it ran) |
| Dynamic arrays (push/pop) | ⚠️ Partial | `.length` and `push` work; `pop` not modeled |
| Inheritance | ⚠️ Partial | Single contract only, no virtual dispatch |
| Events / errors | First-class ops | `revert` prunes its path; `emit` is a verification no-op |
Expand All @@ -119,8 +120,15 @@ Storage references to struct fields through mappings (`Voter storage sender = vo

Mapping storage references (`mapping(...) storage ref = stateVar`) are not supported.

A mapping or array `storage` parameter (`function _credit(mapping(address => uint256) storage m, address k)`)
is rejected: it refers to the caller's storage, and the translator models
parameters as local copies, so a write through it would not reach the state
variable passed in.

A storage reference to a struct state variable (`Info storage d = data;`)
can be read (its fields' values are then unknown), but writing through it
(`d.value = 5`) is rejected: the write would not reach the storage.
can be read: a read `d.value` reads the storage of `data` when it runs, so
it sees writes made after the reference was taken, directly or by a call.
Writing through it (`d.value = 5`) is rejected: the write would not reach
the storage.

Direct state variable access without storage references works fully.
4 changes: 1 addition & 3 deletions StrataSolidity/Obligations.lean
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ def callResultName? (source? : Option String) (name : String) : Option String :=
undoes the translator's renamings, applied only to the names it
introduces (`inputs` are the input names of the procedures): the input
`x_param` is the parameter `x`, the input `x_in` is the pre-state value
`old(x)`, `msg_sender` is `msg.sender`, and `a__b` (a local for the field
`b` of a storage reference `a`) is `a.b`. -/
`old(x)`, and `msg_sender` is `msg.sender`. -/
def displayVarName (inputs : Std.HashSet String) (raw : String) : String :=
let s := match raw.splitOn "@" with
| base :: _ :: _ => base
Expand All @@ -105,7 +104,6 @@ def displayVarName (inputs : Std.HashSet String) (raw : String) : String :=
else if s == "msg_value" then "msg.value"
else if s.endsWith "_param" && inputs.contains s then (s.dropEnd 6).toString
else if s.endsWith "_in" && inputs.contains s then s!"old({(s.dropEnd 3).toString})"
else if !s.startsWith "_" && (s.splitOn "__").length == 2 then s.replace "__" "."
else s
Strata.Solidity.SolcAst.unmangleName s

Expand Down
31 changes: 30 additions & 1 deletion StrataSolidity/SolTranslator/ContractTranslator.lean
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,12 @@ def translateContract (ctx : TransCtx) (contract : Solidity.node SourceRange)
let paramNames := (decls params).map fun
| .VariableDeclaration _ nameAnn .. => nameAnn.val
| _ => ""
let paramLocations := (decls params).map fun
| .VariableDeclaration _ _ _ _ _ _ _ _ storageLoc _ _ => storageLoc.val
| _ => ""
functionSigs := functionSigs ++ [(fnNameAnn.val,
{ isPure := fnIsPure, isView := fnMutAnn.val == "view", memArrayParams, returnTypes,
paramNames })]
paramNames, paramLocations })]
| _ => pure ()

-- Pass 3: Parse contract invariants from NatSpec and set up function context
Expand Down Expand Up @@ -322,6 +325,14 @@ def translateContract (ctx : TransCtx) (contract : Solidity.node SourceRange)
if let some (_, what, _) := envConstants.find? fun (c, _, _) =>
c != "this_address" && readsConstant c parsed then
throw (.unsupported s!"`{what}` is not allowed in an invariant (`{e}`): it changes between transactions")
-- The caller and the value sent belong to one transaction too. An
-- invariant over them would be established for one caller and
-- assumed for the next: with `owner == msg.sender` assumed on entry,
-- `require(msg.sender != owner)` could never pass, and every
-- property after it would be proven.
if let some (_, what) := [("msg_sender", "msg.sender"), ("msg_value", "msg.value")].find?
(readsVariable ·.1 parsed) then
throw (.unsupported s!"`{what}` is not allowed in an invariant (`{e}`): it changes between transactions")
pure parsed

-- Pass 4: translate functions with struct field info, state context, and invariant nodes
Expand Down Expand Up @@ -421,6 +432,24 @@ def translateContract (ctx : TransCtx) (contract : Solidity.node SourceRange)
⟨contractSr, #[]⟩
procedures := procedures ++ [← translateFunction fnCtx implicitCtor]

-- A halt (assembly `return` or `stop`, `selfdestruct`) ends the whole
-- transaction, keeping the state written so far. It is modelled as a
-- return from the function it is in (see `haltLabel`): right in an
-- entry point, whose postconditions and invariants are checked there,
-- but a function that calls one containing a halt would continue after
-- the call, and its remaining code be verified as if it ran. Such calls
-- are rejected.
let implOf (p : Procedure) : Option StmtExprMd := match p.body with
| .Transparent e => some e
| .Opaque _ impl _ => impl
| _ => none
let solidityName (proc : String) := (proc.drop (nameAnn.val.length + 1)).toString
let halting := procedures.filterMap fun p =>
if (implOf p).any containsHalt then some p.name.text else none
for p in procedures do
if let some callee := ((implOf p).map calledNames).getD [] |>.find? halting.contains then
throw (.unsupported s!"the call of `{solidityName callee}` in `{solidityName p.name.text}`: `{solidityName callee}` may end the transaction (assembly `return` or `stop`, `selfdestruct`), and the code after the call would be verified as if it ran")

-- Contract invariants are checked via injection into public functions'
-- pre/postconditions. No separate invariant procedure is needed.

Expand Down
Loading
Loading