Verifying Dimension

A ten-minute path from a clean clone to every claim in the README, plus ways to try to break it. Nothing here needs to be taken on faith: each step runs the code and prints what it checked. For the story first, the film takes two minutes.

The fastest way: one command, with only Docker

The image installs everything on Ubuntu 24.04, as CI does, and runs every offline check (make ci) with no network, in about two and a half minutes:

docker run --rm ghcr.io/femtech-web/dimension              # the published image
docker build -t dimension . && docker run --rm dimension   # or build it from a clone

Any target in this guide runs the same way, such as docker run --rm ghcr.io/femtech-web/dimension make demo; the fork and live targets in step 4 use the network, which docker run has by default. On x86-64 every check runs. On arm64, Docker on Apple silicon included, Fe 26.6.0 has no native backend, so the native-backend checks are skipped and say so; make ci on macOS itself runs them.

Step by step on your own machine instead needs make, curl, Python 3.12, Foundry 1.4.4, and macOS arm64 or Linux amd64 for the native search. Times are from an Apple-silicon laptop.

1. Install (about 1 minute)

make toolchain        # Fe 26.6.0 (5b3f96a), downloaded and checksum-verified into .tools/
make reference-deps   # forge-std, for the Foundry side

2. See both incidents (under 1 minute)

make demo

For each incident this shows:

  1. the mistake, written in Fe;
  2. the compiler rejecting it, which is the protection working;
  3. the fix, as a diff;
  4. the fixed code compiling and passing its test;
  5. the claims that the fork runs saved.
  • Moonwell: MIP-X43's configuration, written against a registry of the real Base feeds, is a type error. The cbETH/ETH feed is not a cbETH/USD feed.
  • Balancer: Balancer's own _upscale line, put back into Dimension's typed pool, is a type error. StableMath only accepts amounts that went through admit.

make show with no argument runs all 23 compile-fail cases the same way.

3. Run everything offline (about 2.5 minutes)

make ci

This is what CI runs on Linux. Each suite prints its claims as holds or FAILS with the evidence, and writes a report to docs/results/<suite>/<platform>.json. The lines to look for:

Output Means
220000 vectors: ... 0 mismatched The Fe port of Balancer's StableMath equals the Solidity, reverts included
holds Do the types alone remove the losses at Balancer's two _upscale sites? Over 4,608 pool states: exact-out swaps 48 → 0 losing operations, exact-out exits 57,990 → 8
holds With the runtime guard added, does any operation lose value per BPT... 0 in every operation kind
holds Can a repeated-exit attacker gain against the faithful kernel... Faithful attacker +20.923 D; with Dimension, −151.416 D
holds Deployed on an EVM, does the faithful pool let a repeated-exit attacker take value from LPs? The same attack against the deployed Fe contracts
gas typed ... gas guarded ... What the safety costs per operation
holds Above -O0, is Dimension's typing free, gas for gas... Typed code on the library itself, against the same code by hand: identical bytes or identical gas
holds Built as a native static library and called from C... The same kernels, linked from C: all 154 values of the batch equal to the EVM's

4. Against the real chains (about 2 minutes each, needs network)

make replay     # the attacker's three transactions, step by step (mainnet forks)
make fidelity   # Ethereum mainnet fork, block 23,717,396
make moonwell   # Base forks from block 42,194,662 to 42,538,949
make feeds      # each declared feed against Chainlink's directory and Base
make live       # the deployment on Base Sepolia, read back from the chain
make wasm       # the same kernels in WebAssembly, every step against the EVM (Rust 1.96+, Node.js)
  • replay forks Ethereum at each of the attacker's three transactions. It replays their 360 swaps on this pool through the three Fe kernels. The faithful kernel must compute every amount Balancer computed, and must end in the state the pool reached once the real transaction runs on the same fork. On the typed and guarded kernels, each transaction's batch reverts. Then an attacker re-plans 90 swaps from the real dust state: on Balancer's arithmetic it cuts the value per share by 43.9%; on the typed and guarded kernels it never gets below where it started.
  • fidelity loads the real osETH/wETH pool's state, at the last block before the attack, into the Fe port. It requires all 669 quotes to equal what Balancer's Vault returns.
  • moonwell compares Moonwell's deployed oracle with Dimension's on the same feeds, at 14 blocks before, during and after the incident. It then tries MIP-X43's mistake at each layer.
  • feeds checks each declared feed against Chainlink's directory and the chain. Moonwell's registry must pass. Two wrong declarations that compile must be rejected, one of which every on-chain check accepts.
  • live reads the deployment on Base Sepolia back from the chain: every receipt, each contract's code against what fe build produces here, each outcome LiveRecorder logged against forge's run of the same batch, and the oracle, the declarations and the vault at the latest block. make live-rehearse deploys it all again on a local fork, with no key.
  • wasm builds Fe with its WebAssembly backend at the pinned commit and compiles the Balancer kernels into the module the site's Live page runs. Every value per BPT across the batch, on each kernel, must equal forge's run of the deployed contracts, and the module must rebuild byte for byte. The unit suites also run on that backend.

All use public RPCs. Set MAINNET_RPC_URL, BASE_RPC_URL or BASE_SEPOLIA_RPC_URL if one is rate-limited.

5. Read the code (five files)

File Why
ingots/dimension/src/flow.fe The whole rounding rule, in about 60 lines
ingots/dimension/src/value.fe admit and settle, the only ways to produce an admitted or settled amount
ingots/balancer_v2/src/pool/typed/math.fe The typed kernel's only door to StableMath
ingots/balancer_v2/src/pool/typed.fe Compare with faithful.fe: the same operations, two rounding sites changed
ingots/moonwell/src/registry.fe The real Base feeds, declared once with their pairs

6. Try to break it

make mutants (with FORKS=1 for the last two) plants 21 realistic bugs, one at a time, in a scratch copy, and requires the check meant for each to fail for the reason expected of it. CI runs it on every change. Its report is docs/results/mutants/. The changes below are ones to try by hand; each was made in a scratch copy, and the stated result observed.

Change Run What happens
In pool/typed.fe, replace admit(amount_out, factor) with Balancer's upscale(amount_out.value(), factor.value()) (importing upscale) .tools/fe-26.6.0/fe check ingots/balancer_v2 error[8-0000]: expected Quantity<_, Out, Admitted>, but u256 is given
In ingots/vault/src/vault.fe, make withdraw credit the assets that leave: v.total_assets.credit(assets) .tools/fe-26.6.0/fe check ingots/vault error[8-0000]: expected Quantity<A, In, _>, but Quantity<A, Out, Given> is given. The withdrawal's own label says the assets leave
In dimension/src/flow.fe, make Out admit with Floor make explore The typed kernel loses exactly as Balancer did (48 and 57,990), and the attacker profits again (+20.923 D). The runtime guard still holds: it rejects all of them. The layers are independent.
In stable/stable_math.fe, drop the + 1 that calc_in_given_out adds make differential Fails: mismatched: calcInGivenOut2, calcInGivenOut3
In moonwell/src/registry.fe, declare ETH/USD with 18 decimals make moonwell Fails: the oracle's constructor checks the real feed's decimals and reverts, so it never deploys ("the Fe oracle must bind the real feeds")
Add unsafe { } anywhere in ingots/moonwell/src make unsafe-policy Fails: unsafe code outside dimension::value::testing

Where each claim lives

Claim Test Report
The port equals Balancer's Solidity contracts/reference/test/StableMathDifferential.t.sol docs/results/differential/
The port equals the deployed pool contracts/reference/test/PoolFidelity.t.sol docs/results/fidelity/
The port computes the attack exactly; the typed kernels stop it contracts/reference/test/AttackReplay.t.sol, fixtures/balancer-v2-exploit/ docs/results/replay/
Types and guard remove the losses ingots/balancer_explorer, pinned by tests/explorer on both backends docs/results/exploration/
The attack and gas on a real EVM contracts/reference/test/PoolAttack.t.sol docs/results/evm/
Moonwell, before, during and after MIP-X43 contracts/reference/test/MoonwellFork.t.sol docs/results/moonwell/
Each declared feed is the feed it claims to be cli/feed_check.py, tests/feeds/ docs/results/feeds/
Each rejected construction, and its fix tests/compile_fail/<case>/ docs/results/compile-fail/
The type machinery is free tests/probes/bytecode/; on the library itself, tests/zero_cost/ with contracts/reference/test/ZeroCost.t.sol docs/results/probes/, docs/results/evm/
A team's own project, created and checked cli/dimension.py, run by scripts/harness/consumer.py docs/results/consumer/
The same on Fe 26.7.0 scripts/harness/compat.py, scripts/toolchain/fe-compat.lock docs/results/compat/
The contracts on a public chain contracts/reference/script/Live.s.sol, deployments/base-sepolia.json, scripts/harness/live.py docs/results/live/
The kernels in WebAssembly equal the EVM interop/kernels.fe, interop/check.mjs, scripts/harness/wasm.py docs/results/wasm/
The kernels as a native library, called from C, equal the EVM interop/kernels.fe, interop/check.c, scripts/harness/native.py docs/results/native/

The site in web/ shows all of these, with the replay and the Moonwell prices charted. make web rebuilds it from whatever reports your runs saved.

What is and is not guaranteed, layer by layer, is in docs/guarantees.md.

Source: JUDGES.md