Repository navigation
Dimension v0.1.0
Dimension is a Fe library in which the meaning of every number in financial
arithmetic is part of its type. Amounts know their token and which way they
move, and their rounding follows from that, always against the trader. Prices
know their pair. External numbers become trusted only at a boundary that
checks them. In this first release, the arithmetic behind Balancer V2's 2025
rounding exploit, and Moonwell's 2026 oracle misconfiguration, does not
compile.
Install
Requires Fe 26.6.0 or 26.7.0. In your ingot's fe.toml:
[dependencies.dimension]
source = "https://github.com/Femtech-web/Dimension"
rev = "57ce4106575a173b9fc51ebb44c3c2243e285cd5" # v0.1.0
name = "dimension"
version = "0.1.0"Fe resolves rev as a full commit hash, not a tag; the hash above is this
release's. Then start from the
quickstart
and follow the
guide.
What is in the library
- Rounding derived from direction.
InandOutflows, and the stages
Given,Admitted,Owed,Settled.admit,settle,scaled_byand
exchangetake their rounding from the direction. A call site never names
one, and the traits are sealed. - Prices and values with their meaning in the type.
Price<B, Q>
composes only through a shared asset.Value<Q, V>rounds collateral down
and debt up, and the two cannot be mixed. - Risk policies checked at compile time. An incoherent loan-to-value or
liquidation bonus does not compile. - Verified boundaries (EVM). Chainlink feeds and rate providers are
declared once, with their pair. Decimals are checked when a contract binds a
feed, and every read checks the answer is positive, fresh and in band. - A runtime guard.
preserves_share_valueis an exact 512-bit check that
the value behind a pool share did not fall. - Zero cost in the measured cases. Typed and hand-written code compile to
byte-identical bytecode at-O1,-O2and-Os.
The full list is in the
changelog.
How it is proven
Every figure below is produced by a make target and saved in
docs/results/.
| Check | Result |
|---|---|
| Fe port of Balancer's StableMath against Balancer's own Solidity | 220,000 vectors over 22 functions, 0 mismatches, 49,100 identical reverts |
| The port against the deployed osETH/wETH pool, at block 23,717,396, the last before the attack | 669 quotes, 0 mismatches |
| The attacker's three transactions, replayed step by step from the real chain state | 360 of 360 steps equal to Balancer's Vault, and every end state equal. On Dimension's typed pool each batch reverts (steps 25, 25 and 22) |
| Exhaustive search over 4,608 pool states, three kernels, on both backends | losing exact-out exits: 57,990 on Balancer's arithmetic, 8 typed, 0 with the guard |
| Moonwell's cbETH market on Base forks across MIP-X43 (14 blocks) | Dimension correct at every block, and identical to Moonwell's own price where Moonwell was right. MIP-X43's configuration is rejected by the compiler |
| An ERC-4626 vault against OpenZeppelin's ERC4626 | 40,000 vectors equal. In 33,684 of them the rounding direction decided the answer |
Realistic bugs planted in the safety-critical code (make mutants) |
17 of 17 caught, each for the reason expected of it, across 7 layers |
| Constructions the compiler must reject | 17 cases, each with a corrected version that passes |
A fresh project taking Dimension by git (make consumer) |
the quickstart builds and passes its tests; a misuse is rejected |
Compatibility
- Fe 26.6.0, which CI pins, and Fe 26.7.0: every ingot type-checks and every
test suite passes on both. - Everything compiles for the EVM. Everything except
value::oraclealso
compiles natively.
Known limits
- A feed declared at the wrong address, with the right decimals and a plausible
answer, passes every check. A registry entry is a reviewed declaration. givenandowedlabel a raw number; labelling it with the wrong direction
is visible in review but compiles.- Not audited. Audit a protocol built on it as you would any other. The full
list of guarantees and limits is in
guarantees.md.
Found along the way
A Fe compiler issue, reduced to a 60-line reproducer and confirmed on 26.6.0 and
26.7.0: -O s emits more code than -O 2
(argotorg/fe#2043).
License
The library (ingots/dimension) is Apache-2.0. The Balancer V2 port and
explorer are GPL-3.0-or-later, as Balancer's license requires.