Skip to content

Releases

Dimension v0.3.1

Choose a tag to compare

@Femtech-web Femtech-web released this 20 Nov 17:56

A fix to the seals. Fe 26.6 does not check a private trait's visibility where
the trait is implemented (argotorg/fe#2036),
so on 0.3.0 code outside Dimension could implement the private Sealed trait
and add a third flow or rounding direction. This release closes that without
relying on the compiler fix.

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 = "5a1aafe80e2f9034242fb6f5ada9b2495685d2ac"   # v0.3.1
name = "dimension"
version = "0.3.1"

Or start a project with the command line, now installable:

pipx install "git+https://github.com/Femtech-web/Dimension#subdirectory=cli"
dimension new my-protocol

What is fixed

Each seal (Rounding, and the one Flow, Stage and Valuation share) now
has a method that takes Key, a struct private to its module. Fe checks a
struct's visibility, so an implementation written elsewhere fails whether it
names the key or leaves the method out:

impl dimension::flow::Sealed for Sideways {
    fn key(_ k: dimension::flow::Key) {}
                                ^^^ `Key` is not visible

Code that never implemented the seal, which was never supported, has nothing
to change. The API is unchanged, and every compiled contract (the pools, the
oracle, the vault) is byte-identical to 0.3.0's.

How it is proven

Check Result
Two new compile-fail cases: a flow and a rounding direction added by implementing the seal from outside both rejected with 2-0003; their corrected twins pass
A new mutant that makes the seal's key public caught by the compile-fail suite
Every contract built from the library, before and after 16 bytecode files byte-identical

Also since 0.3.0, outside the library

  • Live on Base Sepolia: the pools, the cbETH oracle and the vault, deployed
    and attacked on chain; make live reads every outcome back.
  • In the browser: the same Balancer kernels compiled to WebAssembly,
    checked step by step against the EVM (make wasm).
  • Docker: docker run --rm ghcr.io/femtech-web/dimension runs every
    offline check.
  • The command line installs with pipx, outside a clone.

Dimension v0.3.0

Choose a tag to compare

@Femtech-web Femtech-web released this 19 Nov 22:46

v0.2.0 checked an amount's direction against the balance it moves. A balance
was still a bare number, though: nothing said which token it was in, or whether
the protocol holds it or issues it. This release puts both in the type.

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 = "1171eb8339b8fc5bb6f594807f0696fde736ecaf"   # v0.3.0
name = "dimension"
version = "0.3.0"

Or start a project with the command line, from a clone of the repository:
python3 cli/dimension.py new ../my-protocol.

What is new

  • Held<T>, a balance of T the protocol holds, moved by credit and
    debit; Supply<T>, a total of T it issues, moved by issue and
    retire. Each takes only an amount of its own token, in the matching
    direction, in token units. So WETH cannot be credited to a USDC balance, and
    shares coming back cannot be credited to a supply, which would raise it
    instead of retiring them.
  • held and supply_of read a balance or a supply from storage. Like
    given, each call is a label, where a raw number gets its meaning.
  • dimension check lists every label, following imports, aliases,
    re-exports and module paths, and ignoring a local function that shares a
    label's name. CI builds each project against a copy of Dimension whose
    labelling functions cannot be called, and requires the CLI's list to equal
    the compiler's errors.
  • The typed Balancer pool issues the protocol's fee through issue, so
    every movement of its BPT supply is checked.
pair.usdc = pair.usdc.credit(amount)
                             ^^^^^^ expected `Quantity<USDC, In, _>`, but `Quantity<WETH, In, Given>` is given
v.total_shares = v.total_shares.credit(shares)
                                ^^^^^^ no method named `credit` found for struct `Supply`

Upgrading from 0.2.0

0.2.0 0.3.0
held = credit(held, q) held = held.credit(q), with held: Held<T>
held = debit(held, q) held = held.debit(q)
supply = issue(supply, q) supply = supply.issue(q), with supply: Supply<T>
supply = retire(supply, q) supply = supply.retire(q)
a stored u256 held<T>(raw) or supply_of<T>(raw); .raw() to store it back

How it is proven

Check Result
Two new compile-fail cases, each with a corrected twin a deposit credited to another token's balance; returning shares credited to a supply
Two new mutants, one widening credit to any token, one giving Supply a credit both caught
The CLI's labels against the compiler's, in the repository's projects and a fixture of the forms found so far identical
The vault against OpenZeppelin (40,000 vectors), the search, the replay of the real exploit results identical to 0.2.0

Known limits

  • Dimension checks the books against the labels, not the token transfers: that
    each transfer matches its entry is the protocol's own code.
  • The Balancer pool keeps balances in an array by token index, outside
    Held<T>. There the direction and units are typed, and check_factor
    checks at run time that an amount's scaling factor is the one at its index;
    tokens with the same factor are not told apart.
  • Not audited. The full list of guarantees and limits is in
    guarantees.md.

Dimension v0.2.0

Choose a tag to compare

@Femtech-web Femtech-web released this 19 Nov 22:00

Dimension makes the meaning of every number in financial arithmetic part of
its type. Until now, one fact stayed a promise: the direction a raw number is
labelled with when it enters, given<USDC, In>(x). The compiler cannot see
whether x really arrives. This release checks that label against what the
code does with the money.

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 = "docs/releases/v0.2.0.md"   # v0.2.0
name = "dimension"
version = "0.2.0"

Or start a project with the command line, from a clone of the repository:
python3 cli/dimension.py new ../my-protocol.

What is new

  • credit and debit move a balance the protocol holds; issue and
    retire
    move a supply it issues, such as its shares. Each takes only the
    matching direction: an amount labelled as arriving cannot be paid out of a
    balance, and shares labelled as coming back cannot be issued.
  • TokenUnits, a sealed trait: the four functions take only amounts in
    token units, so internal 18-decimal units never reach a raw balance.
  • dimension check lists every label, each place a raw number gets its
    direction, so a review covers exactly those lines.

A deposit labelled, consistently, as leaving the vault rounds its shares up,
in the depositor's favour, and every signature agrees with it. It no longer
compiles: the vault's books refuse it.

v.total_assets = credit(v.total_assets, assets)
                                        ^^^^^^ expected `Quantity<_, In, _>`, but `Quantity<A, Out, Given>` is given

How it is proven

Check Result
The typed Balancer pool and the ERC-4626 vault move every balance and supply through the four functions the exhaustive search (3.14 million operations per kernel), the vault against OpenZeppelin (40,000 vectors) and the replay of the real exploit (360 steps) give results identical to 0.1.0
Labels in the typed Balancer pool 16 of 17 reach one of the four functions; the 17th feeds StableMath, whose signature fixes its direction
Constructions the compiler must reject 2 new cases: a deposit labelled as leaving, and internal units credited to a raw balance, each with a corrected twin
Planted bugs 2 new mutants, one weakening each check, both caught
Cost gas identical or lower at -O1, -O2 and -Os; the typed pool contract is 347 bytes smaller at -O1

Compatibility

Additive: every 0.1.0 item is unchanged. To upgrade, move rev and version
to 0.2.0's.

Known limits

  • A label that never moves a balance or a supply is still checked only by
    review. dimension check lists it.
  • Not audited. The full list of guarantees and limits is in
    guarantees.md.

Dimension v0.1.0

Choose a tag to compare

@Femtech-web Femtech-web released this 19 Nov 16:40

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. In and Out flows, and the stages
    Given, Admitted, Owed, Settled. admit, settle, scaled_by and
    exchange take 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_value is 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, -O2 and -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::oracle also
    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.
  • given and owed label 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.