Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Fe EquiVM proofs

Machine-checked refinement proofs, in Lean 4 with EquiVM, that EVM bytecode produced by the Fe compiler behaves exactly like a high-level specification written in EquiVM's specification language, Stele.

Contracts

Compiled with the Sonatina backend, -O 1, Osaka: WETH9 with Fe bfc795bb4, the others with Fe 26.4.0 (822e80878).

Module Contract Theorem
FeProofs.Constant answer() -> u256 returning 42 feConstantContractCorrect
FeProofs.Identity identity(uint256) feIdentityContractCorrect
FeProofs.NarrowAbi uint8/int8/bool/address echoes feNarrowAbiContractCorrect
FeProofs.ScalarStore one u256 field with a uint256 constructor feScalarStoreContractCorrect
FeProofs.PackedStore StoragePackedArray<8> lanes 0 and 1 fePackedStoreContractCorrect
FeProofs.IndexedPackedStore runtime-indexed StoragePackedArray<8>, index < 64 feIndexedPackedStoreContractCorrect
FeProofs.Deposit Fe deposit contract feDepositContractCorrect (calldata below 2^64 bytes)
FeProofs.ERC20 EquiVM's ERC20 example token written in Fe feERC20ContractCorrect
FeProofs.WETH9 canonical WETH9 written in Fe feWETH9ContractCorrect (string getters under a string-size precondition)

Each theorem covers the constructor and the whole runtime: for every input, the deployed bytecode returns the same data, reverts in the same cases and leaves the same accounts as the contract's Stele specification (SpecSyntax.lean), unless it runs out of gas. EquiVM's refinement relation does not compare event logs or revert payloads.

The deposit contract

feDepositContractCorrect covers every entry point (deposit, get_deposit_root, get_deposit_count, supportsInterface). What it assumes and does not claim:

  • The specification mirrors the Fe source, statement by statement. The theorem does not compare the Fe contract with the Solidity mainnet contract, and does not prove properties of the Merkle tree itself, such as root correctness.
  • Calldata is shorter than 2^64 bytes (calldataBelow2pow64). Fe's ABI decoder relies on its backend's calldata-size bound here; real transactions cannot come close.
  • SHA-256 is specified as the bytecode's STATICCALL to precompile 2, so the theorem holds relative to whatever that precompile returns.
  • The specification keeps the incremented deposit count in a local (size = deposit_count + 1; deposit_count = size), as the bytecode does, instead of reading the count back from storage.
  • The proof is about the exact bytecode in FeProofs/Deposit/creation.hex and runtime.hex. A compiler change that alters that bytecode needs the affected proof steps redone.

The ERC20 token

FeERC20.fe is EquiVM's ERC20 example token written in Fe, and its specification is EquiVM's example specification statement for statement. feERC20ContractCorrect covers the constructor and all six entry points, including the reverts for a short balance or allowance and Fe's overflow panics. The bytecode and the specification both read each balance after the writes that precede it, so the proof does not assume that distinct mapping keys hash to distinct slots.

WETH9

FeProofs/WETH9 is an ingot (fe.toml, src/): canonical WETH9 written in Fe, with WETH9's storage layout (name and symbol as Solidity strings in slots 0 and 1, decimals in slot 2, balanceOf and allowance in slots 3 and 4) and unchecked arithmetic, as in Solidity 0.5. src/sol_string.fe has SolString, a storage field type with Solidity's string layout. Its specification is EquiVM's WETH9 specification statement for statement; only the configuration differs from EquiVM's solc proof:

  • Strings use Solidity 0.8's storage semantics: a length header whose short/long flag contradicts the length reverts, where solc 0.5.16 reads any header.
  • Calldata is decoded strictly: a non-canonical address argument reverts, where solc 0.5.16 masks it.

feWETH9ContractCorrect covers the constructor (for any initial storage), all eleven entry points, including withdraw's value transfer to a caller that may re-enter, and the payable fallback. The runtime theorem assumes feWETH9StorageWF: on a name() or symbol() call, the stored string's ABI encoding is shorter than 2^64 bytes. Fe reverts above that size while the specification returns the string. Only the constructor writes those slots, so a deployed contract satisfies it.

Layout

Each contract directory (FeProofs/<Contract>/) holds the Fe source, the pinned bytecode, the Stele specification (SpecSyntax.lean), files generated by EquiVM's scripts (Bytecode.lean, Selectors.lean, the per-block summaries *Blocks_NNN.lean, and the Spec/Common/Dispatch skeleton), one proof file per function, and the capstone Correct.lean. Unused generated block summaries are pruned (scripts/prune_blocks.py).

FeProofs/Common/ is shared by the contracts:

  • Tactics.lean: rd_step/rd_run apply the generated block summaries from an RD hypothesis (discharging stack bounds, jump destinations and branch conditions from using [...] hints), rd_checked handles Fe's success and return-size checks after an external call, and u256_lits normalizes word literals inside memory terms.
  • Stele.lean: evaluation of locals, literals, binary operators (with ≥, - and + on words), casts and uint256 range checks, local assignment, and the store_get tactic for reading a local through a chain of inserts.
  • Storage.lean: mapping slots (keccak256(key ‖ slot), the hashes as Fe computes them) and reads and writes of m[k] and m[k][k'] for any contract's Solidity layout.
  • Fallback.lean: refinement glue for contracts with a fallback (EquiVM's assumes none).
  • Abi.lean, Memory.lean, Calls.lean: ABI decoding facts (selector word, canonical address, two uint256 arguments), memory facts (adjacent word writes), and call-result checks.
  • Basic.lean, Glue.lean, Constructor.lean, CtorUInt256.lean, PackedByte.lean: dispatcher revert paths and Fe's checked arithmetic and assert! branches, small refinement glue, constructor shapes, and byte lanes of packed storage.

scripts/ has Audit.lean (axioms of every capstone), Unused.lean (declarations no capstone uses), Dups.lean (theorems duplicating another, in this project or its dependencies), Tactics.lean (regressions for the side-goal search of the block-stepping tactics), and the cleanup helpers used to shrink the proofs.

Checking the proofs

lake exe cache get   # Mathlib's prebuilt files
python3 scripts/apply_fast_keccak.py  # verified, isolated Keccak performance patch
lake build

The optional Keccak patch speeds up kernel-checked hashes while preserving the pinned EVM semantics. See proof-checking performance for provenance, measurements, shared selector lemmas, and reproduction commands.

The build fails on any error. To list the axioms each capstone theorem depends on:

lake env lean scripts/Audit.lean

Expect propext, Classical.choice, Quot.sound and a count of native_decide evaluations of concrete bytecode facts, and no sorryAx.

Reproducing the bytecode

Each contract directory holds the Fe source, the compiler settings (*.build.json) and the bytecode the proofs are about. With the Fe compiler at the listed commit, for example:

fe build FeDeposit.fe --standalone -O 1 --out-dir out --emit bytecode,runtime-bytecode

out/DepositContract.bin and out/DepositContract.runtime.bin must match creation.hex and runtime.hex, ignoring a trailing newline. WETH9 is built as an ingot:

fe build FeProofs/WETH9 --contract WETH9 -O 1 --out-dir out --emit bytecode,runtime-bytecode

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages