From b64b80efd5a01f97a44c1d5ed7adf4459599cbc7 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Mon, 12 Oct 2026 16:16:52 -0500 Subject: [PATCH] pola: organize all code by the flow of authority From Mark Miller's SOSP panel statement and Navigating the Attack Surface talk, after a review found two parties' purses in one test scope. Generated-by: Claude Opus 5.5 --- README.md | 2 ++ pola/SKILL.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 pola/SKILL.md diff --git a/README.md b/README.md index 2006c79..1467765 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ Code](https://code.claude.com/docs/en/skills) and ## writing code +- [pola](pola/SKILL.md) — organize all code, tests included, by + the flow of authority: each part gets only what its task needs. - [no-ambient-authority](no-ambient-authority/SKILL.md) — clocks, RNGs, `fetch`, and the filesystem come in as parameters. - [io-between-turns](io-between-turns/SKILL.md) — sync I/O is a pointy diff --git a/pola/SKILL.md b/pola/SKILL.md new file mode 100644 index 0000000..ab2db09 --- /dev/null +++ b/pola/SKILL.md @@ -0,0 +1,53 @@ +--- +name: pola +description: >- + Principle of Least Authority as the way to organize all code: trace the flow of authority, give each component only what its task needs, design APIs around attenuation. Use when writing or reviewing any code, tests included: makers and their parameters, module imports and exports, which objects share a scope, what a facet exposes; when someone says "POLA", "least authority", "who can reach that?", "Bob shouldn't see Alice's purse", or "makeFoo-style actors". The table stakes (no clocks, fetch, or env reached for inside logic) are no-ambient-authority; this is the organizing principle on top. +--- + +# POLA: organize code by the flow of authority + +Mark Miller, [SOSP 50th anniversary panel](https://www.youtube.com/watch?v=br9DwtjqmVI) (3 min): + +> we design abstraction boundaries so that a component's interface only requires arguments that are somehow relevant to its task. If such argument passing were the only source of authority, we would have taken a huge step towards least authority. + +Every reference to anything but immutable data is authority: a purse is the right to spend some assets; a mint, the right to create them; a seat, the right to take part in one deal; a DB handle, every row. Ask of every reference: who holds it, who gave it to them, and does their task need all of it? + +## Recursively, at every level + +[Navigating the Attack Surface](https://www.youtube.com/watch?v=wW9-KuezPp8) (15 min): the same move repeats at each level of composition (OS accounts, apps, modules, objects), and the benefit multiplies, like a Menger sponge. CapMail's main module "receives all of that authority … wiring them together, subdividing the authority … and handing it out piecemeal … written knowing that the address book does not need access to the PGP keyring, so the main module simply doesn't give it that access." + +So at each level, code has two roles: + +- **A wiring layer** (entry point, `main`, test setup, a maker) holds a lot of authority, and its job is to split it and hand out pieces. Keep it small and obvious: it is the TCB at its level. +- **Everything else** gets only the pieces its task needs, as arguments, and can't reach more. + +## In practice + +- **Makers take only what their task needs.** `makeAlice({ usdcPurse, stockDepositFacet })`, not `makeAlice({ ledger })`. +- **Attenuate at API boundaries.** Hand out the narrowest facet that works: a deposit facet rather than the purse; a seat rather than the escrow's admin; a read-only view rather than the DB. When designing an API, decide which facets it has and who should get each. +- **Separate parties get separate scopes.** If two parties' authority shares a scope, a bug or a careless line lets one act as the other. A scope holding both Alice's and Bob's purses is a design error. +- **Tests too.** Tests are where the code's intended authority flow is first written down. Write each party as a `makeFoo`-style actor holding its own authority privately; the test's top level is the wiring layer that creates the parties and introduces them ([sequence-diagram-actor-sim](https://github.com/Agoric/agoric-sdk/blob/master/.agents/skills/sequence-diagram-actor-sim/SKILL.md)). +- **Modules decide what authority enters through imports and leaves through exports.** Export makers, not instances that close over power ([no-ambient-authority](../no-ambient-authority/SKILL.md)). + +```ts +// wrong: one scope holds everyone's purses; Bob's code could spend Alice's +const alice = { usdc: await E(usdc.issuer).makeEmptyPurse(), ... }; +const bob = { usdc: await E(usdc.issuer).makeEmptyPurse(), ... }; +await E(seatB).offer(await E(bob.stock).withdraw(shares(3n)), ...); + +// right: each party holds its own; the test only wires and observes +const makeBob = ({ stockIssuer, usdcIssuer, stockPayment }) => { + const stock = E(stockIssuer).makeEmptyPurse(); // Bob's alone + ... + return { sell: seat => ..., getBalances: () => ... }; +}; +``` + +## Review checklist + +Before committing, for each new maker, scope, and export: + +1. Draw (in your head or as a [wiring-diagram](../wiring-diagram/SKILL.md)) who holds what after this change. +2. Does any non-wiring scope hold two parties' authority, or more than its task needs? +3. Could a narrower facet replace what's passed? +4. Name the wiring layer at this level. Is it small?