Repository navigation
Dimension v0.2.0
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
creditanddebitmove a balance the protocol holds;issueand
retiremove 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 checklists 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 checklists it. - Not audited. The full list of guarantees and limits is in
guarantees.md.