Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
161 changes: 161 additions & 0 deletions .kiro/specs/strata-solidity-next/requirements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Requirements Document — `strata-solidity-next`

## Introduction

This document holds the requirements that change behavior relative to the
**retrospective baseline** in
[`../strata-solidity-baseline/requirements.md`](../strata-solidity-baseline/requirements.md).
The baseline describes what the code did when it was written and introduces
no new behavior; this document is the only place where its `GAP-*` items
are closed.

Every requirement below cites the baseline IDs it modifies or closes, as
`CONTRIBUTING.md` requires. Baseline requirements not cited here are
unchanged.

---

### Requirement 1 — Inheritance: a contract is verified with its inherited members

**Closes:** `GAP-009` (multi-contract inheritance with virtual dispatch),
except for the cases REQ-NEXT-SOL-022..025 report or reject.
**Modifies:** `REQ-SOL-004` (single inheritance via `is`),
`REQ-SOL-005` (diamond inheritance via `baseContracts`),
`REQ-SOL-006` (virtual dispatch across contracts).

**User Story:** As a developer verifying a contract that inherits from
another, I want what it inherits to be part of what is verified, so that a
contract built from base contracts can be specified and proven at all.

**Context.** The baseline's `REQ-SOL-004` and `REQ-SOL-005` say inheritance
is accepted "flattened at the AST level", and `design.md` §12.9 attributes
that flattening to `solast.py`. Neither held once the in-Lean frontend
replaced the Python one: solc's AST lists only the members written in a
contract, with its bases named in `baseContracts`, and
`ContractTranslator.translateContract` read only a contract's own members,
so any use of an inherited member failed to translate. These requirements
replace that behavior.

#### Acceptance Criteria — Flattening

1. REQ-NEXT-SOL-001. THE Solidity_Translator SHALL verify a contract as the
flattening of its transitive bases and itself, so that every inherited
member resolves in the derived contract's own context (its `self`
parameter, its state parameters, its invariants).
2. REQ-NEXT-SOL-002. THE Solidity_Translator SHALL order a contract's bases
by solc's C3 linearization (`linearizedBaseContracts`): for
`contract C is B1, …, Bn`, `L(C) = C :: merge(L(Bn), …, L(B1), [Bn, …, B1])`.
Inherited members are taken most base first, the reverse of `L(C)`.
3. REQ-NEXT-SOL-003. WHERE a more derived contract declares a function with
the name and parameter types (data locations aside) of an inherited one,
or a `receive`, `fallback` or modifier of the same name, THE
Solidity_Translator SHALL verify the more derived declaration and not
the inherited one. A function of the same name with other parameter
types is an overload, and both are verified.
4. REQ-NEXT-SOL-004. WHERE a public state variable shares its name with an
inherited function (which its getter overrides), THE Solidity_Translator
SHALL NOT verify that function in the deriving contract.
5. REQ-NEXT-SOL-005. THE Solidity_Translator SHALL merge inherited state
variables together with their initializers, `constant` values,
`immutable` markers and Solidity type names, and inherited structs,
enums and modifier definitions.
6. REQ-NEXT-SOL-006. THE Solidity_Translator SHALL emit a struct's type
definition and its synthetic constructor procedure once, for the
contract that declares the struct.
7. REQ-NEXT-SOL-007. THE Solidity_Translator SHALL continue to verify every
contract of the file on its own, so that a base's specifications are
checked against the base as well as against each contract that inherits
them; an obligation of an inherited function SHALL name the contract it
is checked in (`ensures … (in D)`).
8. REQ-NEXT-SOL-008. WHERE an inherited function calls a virtual function,
THE Solidity_Translator SHALL call the most derived override of it.

#### Acceptance Criteria — Invariants

9. REQ-NEXT-SOL-009. THE Solidity_Translator SHALL check a base contract's
`@custom:strata invariant`, whether written in the base's NatSpec or on
one of its state variables, at the external entry points of every
contract that inherits it, under the rules of `REQ-SPEC-*` for the
deriving contract.
10. REQ-NEXT-SOL-010. WHERE a base is an `interface` or a `library`, which
have no state, THE Solidity_Translator SHALL NOT take invariants from
it.

#### Acceptance Criteria — Constructors

11. REQ-NEXT-SOL-011. THE Solidity_Translator SHALL run each base
constructor when a deriving contract's constructor (explicit, or the
implicit one that checks the initial state) runs: after every
state-variable initializer, before the deriving constructor and outside
its modifiers, most base first (solc's legacy code generator order).
12. REQ-NEXT-SOL-012. THE Solidity_Translator SHALL run a base constructor
with its own modifiers, in a block that a `return` in it exits, with its
parameters and locals renamed apart from the deriving constructor's.
13. REQ-NEXT-SOL-013. THE Solidity_Translator SHALL bind a base
constructor's parameters to the arguments that the most derived
constructor naming its contract gives (`constructor() Base(7)`),
evaluated most derived first in the scope of that constructor.
14. REQ-NEXT-SOL-014. IF a base constructor's arguments are given in an
inheritance specifier (`is Base(7)`), which the AST the translator reads
does not carry, or not at all (an abstract contract), THEN THE
Solidity_Translator SHALL give its parameters unknown values of their
types.
15. REQ-NEXT-SOL-015. IF a base constructor a constructor runs uses a
struct-valued mapping, THEN THE Solidity_Translator SHALL NOT verify
that constructor, nor the invariants it would establish, and SHALL emit
a warning.

#### Acceptance Criteria — `super` and explicit base calls

16. REQ-NEXT-SOL-016. THE Solidity_Translator SHALL resolve `super.f(...)`
to the implementation of `f` that follows, in the linearization of the
contract being verified, the contract in which the call is written: the
contract that defines the function, modifier or base constructor it is
in.
17. REQ-NEXT-SOL-017. THE Solidity_Translator SHALL resolve `Base.f(...)`,
for a base `Base`, to the first implementation of `f` in `L(Base)`.
18. REQ-NEXT-SOL-018. THE Solidity_Translator SHALL emit each overridden
implementation that such a call reaches, directly or through another
one, as an internal procedure of the deriving contract named
`__base_<DeclaringContract>_<function>`, and no other.
19. REQ-NEXT-SOL-019. THE Solidity_Translator SHALL bind the named
arguments of such a call by name.
20. REQ-NEXT-SOL-020. IF such a call names an overloaded function, or has
no implementation to call, or reaches an implementation that uses a
struct-valued mapping, THEN THE Solidity_Translator SHALL fail with an
`unsupported` error.

#### Acceptance Criteria — Reporting and rejection

21. REQ-NEXT-SOL-021. THE Solidity_Translator SHALL emit the warnings of
`REQ-OUT-*` and `REQ-SPEC-*` for a contract's own declarations only, so
that an inherited declaration is reported once, against the contract
that declares it.
22. REQ-NEXT-SOL-022. IF a contract's linearization includes a contract
that the verified file does not define (an imported base, directly or
through another base), THEN THE Solidity_Translator SHALL emit a warning
naming it and the deriving contract, and SHALL verify the contract
without its members. This is the remaining part of `GAP-009`.
23. REQ-NEXT-SOL-023. IF a contract and one of its bases declare state
variables of the same name (a base's private one), THEN THE
Solidity_Translator SHALL fail with an `unsupported` error: they are
different variables.
24. REQ-NEXT-SOL-024. Note. Overloads whose parameters are all integers or
addresses have the same parameter types in Laurel and are rejected, in
a single contract too (unchanged from the baseline).
25. REQ-NEXT-SOL-025. Note. Base constructors run in solc's legacy order;
the IR code generator (`--via-ir`) initializes each contract's state
variables just before its constructor runs.

#### Characterization

26. REQ-NEXT-TEST-001. THE Golden_Harness SHALL cover, each with true and
false properties: inherited state, internal calls, modifiers,
invariants, virtual dispatch and a getter override
(`test/examples/inheritance.sol`); overloads
(`inheritance_overloads.sol`); base constructors
(`inheritance_constructors.sol`); C3 order
(`inheritance_linearization.sol`); `super` and explicit base calls
(`inheritance_super.sol`, `inheritance_diamond.sol`); and the reported
or rejected cases (`inheritance_imported.sol`,
`inheritance_struct_mapping.sol`, `inheritance_shadowed_state.sol`).
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Changelog

## 2026-10 — Inheritance

A contract is verified with what it inherits. Before, `contract Child is
Base` failed to translate (`Resolution failed: 'n' is not defined`) as soon
as it used anything Base declared; only interfaces and abstract contracts
that declare no state worked. See REQ-NEXT-SOL-001..025 in
`.kiro/specs/strata-solidity-next/requirements.md`; fixtures
`test/examples/inheritance*.sol`.

- Bases are ordered by solc's C3 linearization. Inherited state variables,
functions, modifiers, structs, enums and invariants resolve in the
derived contract's context, and an inherited function calls the most
derived override of a virtual function. An override has the parameter
types of what it overrides; an overload stays. A public state variable
overrides the base function its getter implements.
- Each contract of a file is still verified on its own; an obligation of
an inherited function names the contract it is checked in, `(in D)`.
- Base constructors run when a derived contract deploys: after the
state-variable initializers, outside the derived constructor's modifiers,
most base first, each with its own modifiers and with the arguments the
derived constructors give (`constructor() Base(7)`). An inheritance
specifier's arguments (`is Base(7)`) are not read: unknown values.
- `super.f()` follows the linearization from the contract the call is
written in (in a function, a modifier or a base constructor), and
`Base.f()` calls Base's implementation.
- Reported: a base the file does not define, directly or through another
base. Rejected: `super` of an overloaded function, and a base's private
state variable declared again in a derived contract.

## 2026-10 — Soundness fixes

Each of these made a false property verify; each fix has a fixture under
Expand Down
6 changes: 3 additions & 3 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The tradeoff: JVerify specs are type-checked by javac (you get IDE autocomplete

- **No heap aliasing** — Solidity storage is a flat key-value store. Two state variables cannot point to the same memory. This eliminates the hardest part of heap reasoning that JVerify must handle.
- **No concurrency** — The EVM is single-threaded. No concurrent reasoning needed.
- **No dynamic dispatch** — Solidity has inheritance but external calls are explicit. No virtual method resolution to model.
- **Static dispatch** — external calls are explicit, and the contract a function runs in is known: a virtual function's override and the target of `super` follow from the linearization of the contract being verified, with no run-time types to model.
- **Deterministic execution** — Same inputs always produce same outputs (modulo `block.timestamp`).
- **Simpler language** — No generics, no lambdas, no closures. The translation from Solidity to Laurel is a single file (~2100 lines) vs JVerify's ~30 files.

Expand Down Expand Up @@ -78,9 +78,9 @@ The alternatives: Core is too low-level (no built-in heap model), C_Simp is a to

See `LIMITATIONS.md` for the full supported/unsupported matrix. In summary:

**Working:** Simple and nested mappings, scalar state vars, `old()`, `forall` with `==>`, key-scoped `modifies`, `sum()` aggregation, contract invariants, loop invariants, `keccak256(...)` as mapping keys.
**Working:** Simple and nested mappings, scalar state vars, `old()`, `forall` with `==>`, key-scoped `modifies`, `sum()` aggregation, contract invariants, loop invariants, `keccak256(...)` as mapping keys, inheritance (inherited state, functions, modifiers, invariants and constructors, and `super`).

**Not working:** Struct fields through mappings (Core limitation), counterexamples for quantified specs (`unknown` instead of a model; see LIMITATIONS.md), external calls/reentrancy, inheritance, assembly.
**Not working:** Struct fields through mappings (Core limitation), counterexamples for quantified specs (`unknown` instead of a model; see LIMITATIONS.md), external calls/reentrancy, assembly, a base contract in another file.

## Why does Solidity need fewer simplification passes than Java?

Expand Down
2 changes: 1 addition & 1 deletion LIMITATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ This is not practical for verifying existing contracts but works for new designs
| 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 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 |
| Inheritance | ✅ Modelled | A contract is verified as the flattening of its bases and itself, ordered by solc's C3 linearization: inherited state, functions, modifiers and invariants are checked in the derived contract's context (an obligation of an inherited function names it: `(in D)`), and an inherited function calls the most derived override. Base constructors run before the derived one, with their modifiers and the arguments the derived constructors give. `super.f()` follows the linearization from the contract the call is written in; `Base.f()` calls Base's implementation. Not covered: a base in another file (reported; its members are absent), the arguments of an inheritance specifier `is Base(7)` (unknown values), `super` of an overloaded function and a base's private state variable declared again (rejected) |
| Events / errors | First-class ops | `revert` prunes its path; `emit` is a verification no-op |

## Storage References
Expand Down
5 changes: 4 additions & 1 deletion StrataSolidity/SarifOutput.lean
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ private def classifyRule (vcr : VCResult) : String :=
else if summary == "divisor is non-zero" || summary == "modulus is non-zero" then
"strata/division-by-zero"
else if has label "loopinv" then "strata/loop-invariant-fail"
else if summary.isEmpty && label.startsWith "assert" then "strata/assert-fail"
else if label.startsWith "assert" && (summary.isEmpty || summary.startsWith "assert") then
-- (An `assert` in an inherited function carries its text and the
-- contract it is verified in as summary.)
"strata/assert-fail"
else "strata/unknown"

/-- How an obligation came out, shared by every output format. -/
Expand Down
Loading
Loading