Skip to content

Dimension v0.3.0

Choose a tag to compare

@Femtech-web Femtech-web released this 19 Nov 22:46
· 12 commits to main since this release

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.