Seedelf-Wallet

seedelf-verification

Machine-checked proofs of exactly when each of Seedelf’s on-chain scripts accepts a transaction. Seedelf is a stealth wallet on Cardano. The proofs also cover the Lovejoin v2 scripts: Lovejoin is the mixer the Seedelf Wallet uses. This page is for anyone who reads “formally verified” and wants to know what it means: what’s proved, about which bytes, in what model, what isn’t covered, and how to check it.

CLAIMS.md is the one-page version: what the proofs let us claim, and where the claim stops.

The scripts

Seedelf’s three, variant 1 of its contracts, the one deployed on Cardano:

Lovejoin v2’s five. All but reference_holder are templates, which each pool applies to its own parameters:

How it’s proved

All three Seedelf scripts are proved in Lean’s kernel, with no Blaster (Seedelf/Every/). For every transaction, with no step limit, any number of signatories and any mint, each accepts exactly when a statement written in its Aiken source’s terms holds (walletAccepts, policyAccepts); always_false never accepts. That those statements say what the source says rests on reading them, not on a proof (Not proved, and why). The Blaster modules below are a cross-check, by another route, of the same properties.

Lovejoin’s proofs are here too, in Lovejoin/: v2’s, and scenario proofs of its older classic mainnet pool, which the claim leaves out. CLAIMS.md and Lovejoin/AnyTx/README.md say what they cover and what they leave out. Audit/ holds the project’s own review of the proofs (its README). It covers the scenario proofs, not the kernel proofs the claim rests on.

What’s proved

In Lean’s kernel

On the same bytes, for every V3 script context (any value of CardanoLedgerApiBlaster’s type for the transaction, redeemer and purpose the ledger hands a Plutus V3 script), and for any context Data at all. Each theorem is about the deployed program’s own run (cekExecuteProgram). When the condition holds, the run returns () after some number of steps, which the ledger accepts if the transaction’s execution budget covers it; otherwise it reaches Error, and at no step count does it return a value (Halt). No step limit, no layout, no ledger hypothesis, Lean’s own axioms alone. Seedelf/Every/README.md has the modules.

Script Theorem Accepts exactly when
wallet Seedelf.Every.wallet_accepts_iff walletAccepts, wallet.ak: a spend, the redeemer a Proof { z_b, g_r_b, vkh }, and then no datum, any datum that isn’t a Register, or a Register for which schnorr.prove holds (schnorrProve) and vkh is among the signatories, however many there are
policy Seedelf.Every.policy_accepts_iff policyAccepts, seedelf.ak: a mint, the redeemer a bytestring, a mint of exactly one line (policy, name, amount), an input; then exactly one of the burn (own policy, take(tkn, 4) = 5eed0e1f, -1) and the mint (own policy, token_name.generate of the first input and the tag, 1). An index past 255 fails, for a burn too. The byte slice is PlutusCoreBlaster’s own
always_false Seedelf.Every.always_false_errors never: any argument reaches Error

wallet_exec_iff and policy_exec_iff state the same of any context Data (walletBool, policyBool, the compiled code read back).

By Blaster

On the same bytes, in every transaction. Every field a script doesn’t read is any Data, values the ledger never produces included (AnyTx.lean). Only what a script walks or takes apart is fixed, one scenario per shape. AnyTxShapes and PolicyShapes prove, kernel-checked, that the scenarios are every V3 context there is. The last column counts each row’s theorems.

Module Property Theorems
AlwaysFalseAnyTx always_false reaches Error whatever its argument: every V3 context, and any other Data 1
WalletPurposeAnyTx The wallet is spend-only, with any TxInfo, redeemer and purpose payload 5
WalletRedeemerAnyTx A redeemer that isn’t a proof, Constr 0 [B _, B _, B _], reaches Error, with any TxInfo, output reference and datum. 22 shapes 22
WalletNoLockAnyTx A datum that isn’t a Register locks nothing: a UTxO whose datum isn’t a Register returns unit, which the ledger accepts, with any well-formed proof, TxInfo and output reference. 18 shapes 18
WalletAnyTx, …Two, …Three, Signers/Signers4 to Signers128 The wallet’s core property: a Register UTxO moves iff the Schnorr check holds and vkh is among the signatories, for every count of them from none to 128, every other field any Data. Every run returns unit or reaches Error 13 + 250
AnyTxShapes Every V3 context is one of the wallet’s scenarios: another purpose, a redeemer that isn’t a proof, a datum that isn’t a Register, or a Register with k signatories. Kernel-checked 10
PolicyPurposeAnyTx The policy is mint-only, with any TxInfo, redeemer and purpose payload 5
PolicyRedeemerAnyTx A redeemer that isn’t a B (the personal tag) reaches Error, with any TxInfo and policy id 4
PolicyLinesAll, LinesAllAnyMint A mint of two lines or more fails, at every length. So does any mint Data that doesn’t flatten to exactly one line, and any redeemer that isn’t a B. Any other field, inputs, signatories and policy id. Kernel-checked, by induction over the mint (LinesAllLoops, on LinesAllCek’s evaluator), with no step limit 15
PolicyLinesAnyTx, …FourAnyTx, …FiveAnyTx The same by Blaster, as a cross-check: no lines, and 2 to 5 lines in every arrangement over policies 31
Slice/’s Rule The policy’s rule for one line: it passes iff the first input’s index is a byte, the line is the policy’s own, and it burns one token whose first four bytes are 5eed0e1f, or mints one token named as token_name.generate names the first input and the tag. Every run returns unit or reaches Error. Every value symbolic, every unread field any Data 258, combined into 2
PolicyShapes Every V3 context with an input and a mint the ledger accepts is one of the policy’s scenarios. Kernel-checked 15

So, for every transaction:

The scenario modules are narrower: each fixes the fields its script never reads (an empty transaction from Scenario.lean), and the modules above restate each of them in every transaction. The success theorems in PolicyBurn and PolicyMint don’t build, since Blaster can’t decide Char’s BitVec (Not proved, and why); PolicyBurn’s two failure theorems, below, do. Slice/ proves the success directions over an opaque slice instead (What a ✅ is worth).

Module Property Theorems
AlwaysFalse always_false reaches Error, for any purpose and redeemer 1
WalletPurpose The wallet is spend-only: minting, rewarding, certifying, voting and proposing reach Error 5
WalletNoLock A datum that isn’t a Register locks nothing: a UTxO whose datum isn’t exactly Some(Constr 0 [B _, B _]) is spendable with any well-formed proof. 18 datum shapes, which together cover every datum but a Register (listed in the module) 18
WalletRegister The wallet’s core property: a Register UTxO moves iff the Schnorr check holds and vkh signed. The check is the Aiken source’s prove, in its order: z and c = blake2b_224(g ‖ g_r ‖ u ‖ vkh) decode into the scalar field, and g^z = g_r · u^c. One input and one signer; g, u, z, g_r, vkh and the signer all symbolic 1
PolicyAmount Any amount other than ±1 fails 1
PolicyForeign A mint or burn whose one line is another policy’s fails 2
PolicyBurn No 5eed0e1f token burns when the first input’s output index is 256 or -1 2

What a ✅ is worth:

Lovejoin v2

Kernel-checked in every transaction (Lovejoin/AnyTx/README.md): mix_box (Lovejoin.AnyTx.BoxPurposesAll.every_context_iff), reference_holder (Lovejoin.AnyTx.PurposesKernel.reference_holder_every_context_errors), mix_logic (Lovejoin.Every.Readable.mix_logic_accepts_iff: both withdrawals, the Owner and the Mix, and its publish) and one_shot_mint (Lovejoin.Every.Readable.one_shot_mint_accepts_iff: the launch). Each characterizes its script in every V3 context, at any list length, with no step limit and on Lean’s own axioms alone. reference_holder errors in every context. mix_box’s theorem is an iff with no hypothesis. mix_logic’s and one_shot_mint’s are iffs under the ledger’s value rules: mix_logic’s on the values of the reference inputs, one_shot_mint’s on the mint and the outputs’ values (CLAIMS.md, Where it stops). mix_logic’s and one_shot_mint’s are stated in the Aiken source’s terms (validate_owner, walk_outputs, verify_pre, datum_sane, …), each proved equal to what the bytes do. fee_contract is out of scope: no Seedelf transaction uses it.

Not proved, and why

What the proofs leave out. The model’s own limits (the machine, the decoder, the opaque crypto) are under What a ✅ is worth above; CLAIMS.md’s Where it stops adds the ledger rules assumed and execution budgets.

Out of the claim

Not proved yet

Proved in the kernel, not yet by Blaster

Blaster fixes the length of every list a script walks (rule 4), so its cross-checks stop at five mint lines and 128 signatories, where the kernel’s theorems have no bound (Every transaction, by layout). Past those lengths, only the kernel’s theorems hold. One property more is proved in the kernel but not by Blaster, and closing that gap needs Blaster or PlutusCoreBlaster to change, not the scripts. Seedelf/Every/ proves it over PlutusCoreBlaster’s own slice, since the kernel never has to decide anything about a slice, only carry it. Upstream/ holds a minimal reproduction of its blocker, with controls (./check.sh upstream).

Property Blocked by
By Blaster, the policy’s rule over PlutusCoreBlaster’s own slice rather than the alias (PolicyBurn’s and PolicyMint’s success directions). Proved in the kernel: policy_accepts_iff sliceByteString is take/drop on the List Char, so any slice of a symbolic bytestring reaches Char’s BitVec, even lengthOfByteString (sliceByteString 0 4 bs) ≤ 4 (Upstream/ByteStrings). Slice/ proves the rule over the opaque alias instead, which says what the bytes check for any interpretation of the slice

Running it

You can re-run every proof yourself. It takes Linux with systemd, since check.sh caps each module’s memory with systemd-run --user, and up to 16 GB of memory and 30 minutes a module.

What it needs. elan, which installs the Lean that lean-toolchain pins, 4.24.0. Z3 5.3.1 or later on PATH, for everything Blaster proves; seedelf-every needs no Z3. The pinned Blaster commit sends Z3 a simplifier (recfun-finder) that 5.3.0 introduced; PlutusCoreBlaster’s README still says 4.15.2, which fails every proof that reaches Z3. python3, with which check.sh reads each module’s build log (without it every module reads NO TRACE), and which runs the generators and readers. Aiken, for the concrete/ cross-checks; v2’s extract needs Aiken v1.1.24.

The pins. The proofs build on forks of Lean-blaster and PlutusCoreBlaster, at pinned commits, because fixes they need aren’t all upstream yet. lakefile.lean pins all three tools, and lake-manifest.json holds the full hashes:

Slice/ is a package of its own, with the same pins but one: PlutusCoreBlaster at 96261cc, which is the main package’s pin plus an opaque SliceByteString (see What a ✅ is worth). So the alias changes no other proof.

The scripts’ bytes are committed, as .hex files. The extract scripts rebuild them and check each against its hash:

./extract.sh            # the deployed scripts, hash-checked, into Seedelf/Scripts/ and concrete/build/
./extract-lovejoin-v2.sh      # v2's templates, from a Lovejoin clone at 29573c5 (LOVEJOIN_V2=), with Aiken v1.1.24
./extract-lovejoin.sh         # the classic pool, from Lovejoin's c1239fb (LOVEJOIN=)
./check.sh              # standard Seedelf modules, cheapest first; or ./check.sh Seedelf.PolicyBurn
./check.sh seedelf-any-tx     # the every-transaction modules alone
./check.sh seedelf-signers    # the wallet with 4 to 128 signatories (python3 -I gen-seedelf-signers.py writes them)
./check.sh seedelf-policy-any-tx   # the policy in every transaction, where it needs no slice
./check.sh seedelf-slice      # the policy's one-line rule, in its own package (python3 -I gen-seedelf-slice.py)
./check.sh seedelf-every      # all three scripts in every transaction, kernel-checked: no Z3 (16 GB, 30 min a module)
./concrete/wallet_datums.sh   # cross-checks with Aiken's evaluator
./concrete/policy_burns.sh
./concrete/wallet_register.sh

After an extract run, delete the Scripts modules’ builds. Lake, Lean’s build tool, doesn’t track the .hex files the Scripts modules read, so a changed script rebuilds nothing and check.sh replays the old results as ok:

rm -f .lake/build/lib/lean/{Seedelf,Lovejoin,Lovejoin/V2,Lovejoin/Template}/Scripts.{olean,trace} Slice/.lake/build/lib/lean/Slice/Scripts.{olean,trace}

Never build bare (lake build). check.sh builds each module in its own memory-capped scope (8 GB and 10 minutes; lovejoin-every, seedelf-every and their modules 16 GB and 30 minutes; CAP= and LIMIT= to change), which Linux kills past the cap. An uncapped build has used over 50 GB. The first build fetches and compiles the dependencies and takes a while.

To check the standard Lovejoin and Seedelf proof suites, including the separate Slice package, from this directory:

./check.sh lovejoin && ./check.sh lovejoin-v2 && ./check.sh lovejoin-any-tx && ./check.sh lovejoin-every && ./check.sh seedelf-every && ./check.sh seedelf-slice && ./check.sh

lovejoin-every builds the 51 modules its theorems import from elsewhere first, then its own 25, at 16 GB and 30 minutes a module. PolicyBurn and PolicyMint report EXPECTED, which fails no run: their success theorems fail on BitVec by design (Not proved, and why), as expected-failures.txt records. A failure there that the list doesn’t record, a counted theorem’s ✅ missing or Undetermined among them, reports FAILED and says what differs. Any FAILED needs a look.

The runner returns a nonzero status if any module fails, unless it fails just as expected-failures.txt records (EXPECTED). It checks Lake builds, and a module that builds but logs a Blaster check as Undetermined fails too (UNDETERM), as does one whose log shows a sorry or a native_decide (SORRY), both read from the module’s own build log, its trace. A run’s status covers the modules it lists and every module of this package they import: an import the run doesn’t list is read from its own trace and reported under its own name (UNDETERM Lovejoin.V2.MixAnySpec (an import of …)), and the summary’s last line counts them. A dependency’s module counts only when its build fails. A module that fails to build, times out or is killed loses its old build files, and so does a dependency’s module that fails, since Lake keeps the last good trace and the readers would take it for this run’s; one that never started, because an import failed, keeps its build. Once a build passes, each trace the runner read is dated to the build’s start, since Lake replays a log only for the source it was built from: a source written again with the same bytes (a checkout, a stash) reads as checked once a run has read it. python3 -I tally.py Seedelf (or Lovejoin, Slice/Slice) reads what the builds left, each module’s ✅ against its source; a module with no build, resting on one that has none, here or in a dependency, or whose trace is older than its source, isn’t ok, and ./check.sh <module> settles the last (./check.sh seedelf-slice <module> for one of Slice/’s). bash test-tools.sh checks these rules in check.sh, tally.py, Audit/count.py, Audit/run-all.sh and the diag scan, on fake packages: no Lean, about ten seconds, and CI runs it on every pull request that changes it or a file it reads (verification-tools.yml). This command excludes the separate audit and upstream reproductions. For the longer audit and its warning counts, see Audit/README.md.

That mainnet’s v2 pool runs these bytes is checked by a test in the wallet’s WebAssembly crate, which needs no Lean: from seedelf-platform/, cargo test -p seedelf-wasm --test lovejoin_proven_bytes_test. It checks that the template files here match the bytes the wallet derives pools from, and derives the live v2 pool’s NFT policy (fcb3f5ec5f58d8fc31cf60408b77a1fe4f431880dc810bd12e8a9aa2), mix_logic and mix_box from them, hash for hash.

Questions and reports

For contributors

How each family is built and changed, the plans and the records: Seedelf/Every/README.md, Lovejoin/Every/README.md and Lovejoin/AnyTx/README.md. The last also says what to do when a Lovejoin property comes back Falsified. The two sections below stay here, since the proofs’ comments cite them.

Found along the way

Writing a property

Rules for a new Blaster property, numbered as the modules’ comments cite them.

  1. Measure steps first. Blaster’s machine counts return steps too, so it takes about twice what the chain’s cost model charges (wallet: 409 steps against a cost-model 233). Add the scenario’s concrete run to Steps.lean and set the limit above it.
  2. Failure is isUnsuccessful, never ¬ isSuccessful. A run cut off by the step limit is neither (isExhausted), so with too small a limit ¬ isSuccessful holds of every run, and proves nothing.
  3. Pair a failure property with a run that passes. A malformed scenario fails for its own reasons; Steps.lean shows the same context halting when it’s valid.
  4. Symbolic only what the property needs. Every symbolic value the script branches on splits the symbolic run, and the splits multiply. Never symbolic: a list the script walks, or a bytestring it slices (keep the branch out of the scenario: a hypothesis excluding it still leaves it in the run). An opaque call doesn’t split: WalletRegister’s six symbolic bytestrings, through the scalar decode and the crypto builtins, take about a second.
  5. Small modules. A module killed at the cap loses all its messages, including the ✅ before it.
  6. Read a result through a match, never a whole State. prop … = State.Halt (…) makes Blaster declare the CEK datatype, constants and all. Match on the halted value, as isSuccessful does.
  7. A spec over opaque builtins must call them exactly as the script does: the same function, the same arguments, in the same order. Commutativity is lost on the solver. Steps.lean’s concrete check of the spec (schnorrAccepts on a real proof) catches a wrong spec, but not a wrong order.
  8. Give each builder a control Blaster must falsify: one of the theorems over it with a condition left out, or its outcome turned around, as #blaster (gen-cex: 0) (solve-result: 1). Each Blaster goal is its own query over its own prepared builder, so a control probes that builder alone. Were the solver’s background over it contradictory (Lean-blaster #194), every statement over that builder would come back Valid, the control too, which then prints “❌ Unexpected Valid” and fails the build.