One kernel, written in Fe, compiled for the chain and for your terminal
HARDSTOP is a standalone vault for one token and one agent. Its rules are a pure Fe module with no storage, no calls and no logs, so the same source builds into the contract that holds the money and into a native command-line tool.
- Language
- Fe 26.6.0
- Licence
- MIT
- Status
- Unaudited contest prototype
The kernel in brief
kernel.fe holds three ideas. decide answers whether one payment may go through and, if not, why. amend applies a change by the owner: tighter parts at once, looser parts after the cooling period. exposure returns the most the agent can move between two moments.
No function in the kernel has a uses clause, so the compiler rejects any attempt to read storage, make a call or emit a log from it. The vault gathers the facts, hands them over, and does what the kernel decided.
These two functions are the whole of the slow-to-loosen rule, copied unchanged from the source:
/// Whether `to` lets the agent do anything `from` does not.
pub const fn loosens(_ from: Policy, to: Policy) -> bool {
to.per_payment > from.per_payment
|| to.per_window > from.per_window
|| to.valid_until > from.valid_until
|| (from.paused && !to.paused)
}
/// The owner proposes `proposed` at `now`.
///
/// Whatever in the proposal is tighter than the policy in force applies
/// immediately. If any part is looser, the whole proposal is queued and
/// takes effect `cooling_secs` later; a proposal with nothing looser clears
/// the queue. So a limit can drop in one step but can only rise after the
/// cooling period, and any later tightening cancels a pending rise.
pub const fn amend(_ proof: own OwnerProof, rules: Rules, proposed: Policy, now: Instant) -> Rules {
let in_force = rules.current(now)
let active = meet(in_force, proposed)
let queued = if loosens(active, to: proposed) {
Queued { policy: proposed, effective_at: matures_at(rules.schedule, now) }
} else {
Queued::none()
}
Rules { schedule: rules.schedule, active, queued }
}From fe/src/kernel.fe. A test in this site’s suite fails if the excerpt stops matching the file.
Run it
# in fe/ (Fe 26.6.0)
fe test # kernel, adversary and vault tests on the EVM
fe test --backend native # the same kernel and adversary tests, as a native program
fe build --backend native # builds ./out/hardstop (x86-64 Linux or AArch64 macOS; use WSL on Windows)
./out/hardstop decide … # one verdict from the native kernel
# in web/
npm test # the compiled vault against the native kernel, plus tests that move the clockdecide takes twenty decimal numbers. This is its usage text, from cli.fe:
hardstop decide RULES LEDGER amount nonce from_agent to_approved now
RULES = anchor window_secs cooling_secs
per_payment per_window valid_until paused
q_per_payment q_per_window q_valid_until q_paused q_effective_at
LEDGER = window spent next_nonce
decide prints: code detail window spent next_nonceReason codes
pay returns one byte: 0 when the payment was made, otherwise why it was refused. The names come from Reason in kernel.fe; the sentences are what this site shows a person, with sample amounts and dates filled in.
| Code | Name | Example of what a person reads |
|---|---|---|
| 0 | Allowed | Inside every limit. $16.00 left today. |
| 1 | InvalidPolicy | This vault was created with a broken schedule, so nothing can be paid from it. |
| 2 | Paused | You paused this agent. Nothing it asks for is paid until you resume it. |
| 3 | NotAgent | This request did not come from the agent you authorised. |
| 4 | NotYetActive | These rules start on 15 Jan 2027, 08:00 UTC. |
| 5 | Expired | The agent's permission ended on 15 Jan 2027, 08:00 UTC. |
| 6 | WrongNonce | This request was already used, or came out of order. The agent must send a new one (request 3). |
| 7 | NonceExhausted | This vault has used up its request numbers. Create a new one. |
| 8 | ZeroAmount | The agent asked to pay an amount of zero. |
| 9 | RecipientNotApproved | This recipient is not on your approved list, or was added so recently that its waiting period has not ended. |
| 10 | OverPaymentLimit | One payment may be at most $10.00. |
| 11 | OverWindowLimit | Only $2.00 is left today. |
From pay, a caller that is not the agent never gets code 3: the contract reverts with NotAgent() instead, so strangers cannot write to the log. Owner-only functions revert with NotOwner() for anyone else, the agent included.