An agent proposes.
It chooses an approved action and a quantity. The pool’s owner defines the rules; agents cannot rewrite them.
Open-source Rust / NEAR contract
12 MW total. 4 MW protected. Every ship must pass the same gate.
An agent can have permission to act and still make the shared situation worse. Even well-behaved agents can overbook the same capacity. Our security boundary checks authority and the combined consequences—including commitments that have not finished yet.
It chooses an approved action and a quantity. The pool’s owner defines the rules; agents cannot rewrite them.
The contract evaluates the resulting shared state, including pending commitments. Hard limits must hold and the configured error score must not increase.
An allowed action reserves capacity before dispatch. A denied action can be revised and checked again. Unknown execution outcomes keep their reservations.
What is “system energy”? A policy-defined measure of imbalance: unmet work, excess bookings, uneven stock, or stress-loss exposure. The Lyapunov-style check asks whether an agent’s commitment makes that score worse. It does not predict every future event.
V(next) ≤ V(now)Start at the space station: a ship must wait because docking would consume protected power. Then explore compute, delivery capacity, inventory, worker budgets, and risk headroom—all using the same Rust gate.
Research reserves 4 blocks. Evaluation reserves 2. Data asks for 4 more.
10 fits the hard ceiling of 12, but energy would rise 20 → 44. The pool stays at 6.
Run the next decision: Data explicitly requests 2. Energy falls 20 → 8; bookings reach 8.
Loading the first request…
Run the first decision to see what the lock checks.
Lower means less imbalance under this policy. Denied requests do not change the pool.
Each request leaves an explanation here.
A suggestion changes nothing until you explicitly submit it.
Turn this off to inspect pending commitments. Completion and confirmed nonexecution are simulated provider evidence.
Pending work already counts. An unknown outcome retains its reservation until the registered executor confirms what happened.
| ID | Action | Units | Status | Simulate evidence |
|---|
NEAR holds the shared policy and reservation ledger. Each submission checks the authenticated caller and current state, then reserves capacity in one contract call. Cross-contract dispatch and authenticated callbacks connect that decision to execution.
Why put the gate on NEAR? Independent agents share one contract-owned ledger and a common execution authority. The synthetic executor rejects direct agent calls: changing a browser or skipping a client-side check cannot authorize execution. Real providers would need the same enforced adapter boundary.
// A proposed commitment
check_authority(caller, recipe);
check_version_and_freshness(request);
next = reserve(state, recipe, quantity);
require(hard_constraints_hold(next));
require(energy(next) <= energy(state));
// Reserve first. Dispatch second.
commit(next);Recovery from an externally disturbed state has additional checks. See the full specification for exact semantics.
Bounded data, checked integer arithmetic, fixed recipes. No NEAR dependency in the core’s default build.
The synthetic adapter accepts execution only from the lock. Callback failure does not automatically release a commitment.
Accepted reservations do not increase the configured potential. External events can. Lean model proofs, TLA+ checks, and Kani verification of the Rust core target v1.1.0. Explore the formal verification.
Everything that makes the six scenarios different is data. Describe your shared resource in one JSON policy, then deploy the same tested Wasm.
Each metric is a quantity the pool tracks, with hard min and max bounds: GPU blocks, MW, inventory, budget.
Add one metric per window or bucket you need to protect separately. A protected reserve is simply a lower max on the shared bucket.
Each term scores imbalance: Target distance, Excess over a line, or Deficit below one. Admission requires the total never rises.
Weights decide which problems matter most. Hard bounds and the score are separate checks; a lower score never buys a breach.
A recipe fixes who may ask (actor), who executes (executor), what is reserved, and what completion changes. Agents choose only a recipe and a quantity.
requires chains recipes, so a later step can need an earlier one to finish first.
Policy is immutable once new runs, so review it first. Deploy and initialize in one transaction from the contract’s own account.
Then check the code hash, preview as an agent, and submit.
{
"name": "api-budget",
"owner": "you.near",
"max_age_seconds": 0,
"metrics": [{ "name": "Requests booked", "unit": "req/min",
"initial": 0, "min": 0, "max": 100 }],
"terms": [{ "metric": 0, "target": 80,
"weight": 10, "shape": "Excess" }],
"recipes": [{ "name": "Crawler: batch", "actor": "crawler.near",
"executor": "api-gateway.near",
"reserve": [1], "complete": [0],
"max_units": 40, "requires": [] }]
}# 1. Build both Wasm contracts and a provenance manifest
./scripts/build.sh
# 2. Deploy and initialize the lock in one transaction
# (near-cli-rs syntax; check `near contract deploy --help` for your version)
near contract deploy pool.you.near \
use-file target/wasm32-unknown-unknown/release/pool_contract.wasm \
with-init-call new json-args "$(jq -c '{config: .}' config.json)" \
prepaid-gas '100 Tgas' attached-deposit '0 NEAR' \
network-config testnet sign-with-keychain send
# 3. Deploy and initialize the executor named in each recipe's "executor"
# field (api-gateway.near in the example). The bundled pool_executor.wasm
# is synthetic; use your own adapter for real resources. Without an
# initialized executor, the first dispatch ends in an "unknown" outcome
# and the reservation stays held.
near contract deploy api-gateway.near \
use-file target/wasm32-unknown-unknown/release/pool_executor.wasm \
with-init-call new json-args '{"lock":"pool.you.near","operator":"you.near"}' \
prepaid-gas '100 Tgas' attached-deposit '0 NEAR' \
network-config testnet sign-with-keychain send
# 4. Read the pool back and compare the code hash to your build manifest
near contract call-function as-read-only pool.you.near get_pool \
json-args {} network-config testnet now
Use the deployment checklist for account setup, then open the NEAR console with your account and expected code hash.
Replace every executor with an adapter you control. The bundled executor is synthetic: it proves the gate, not a connection to your GPUs, warehouse, or funds. A real adapter must implement the execute and status protocol, idempotency, and authoritative cancellation, and it must leave agents no route around the lock.
Policy and principals cannot be edited after initialization. A pool holds at most 32 metrics and 32 recipes, and keeps its 256 most recent commitments; a new one replaces the oldest once that has ended. The contract is not independently audited. Formal verification of v1.0.0 found issues; v1.1.0 fixes them. Future versions are likely to add more capabilities, check that the contract version you use has the capabilities you want (sometimes simpler is better). Test on testnet first.
A recipe ID, an exact integer quantity, the state version it reviewed, and a short expiry. Recipes fix the actor, executor, effects, and prerequisites. The agent cannot supply its own risk estimate or ledger delta.
{
"recipe": 0,
"units": 2,
"version": 4,
"expires_at": "current time + 10 minutes"
}Illustrative request: the real expiry is an integer timestamp. A stale version is rejected and must be reviewed again.
Unknown execution outcomes keep their encumbrance. Before dispatch, the actor or owner can cancel. After dispatch, release requires definitive nonexecution evidence from the registered executor.
The kernel checks the configured bounds and potential against a modeled state. It does not guarantee fairness, profitable trades, truthful external observations, or eventual completion. The immutable policy and registered evidence authorities are part of the trust boundary.
Compute jobs, deliveries, worker payments, and financial positions in this explorer are synthetic. Real-world enforcement requires an adapter without a route around the lock. Dedicated multi-level verification of v1.1.0 includes model proofs, checks, and Kani on the Rust core. The verification PR reports settlement/liveness findings. v1.1.0 fixes them (findings). The contract is not independently audited.
Run a scenario decision to inspect its response.
The deliverable is an MIT-licensed contract for the NEAR ecosystem. Fork it, define the shared resources and policy for your application, and connect an enforced executor. The six scripted scenarios show how the same admission rule applies across businesses.
The GPU trace includes a request that passes hard capacity bounds but raises energy. It is denied without reserving resources.
Inspect the Rust-generated trace ↗NEAR sandbox tests attempt direct executor calls and agent-authored settlement. Both fail; registered execution evidence is required.
Inspect the bypass tests ↗Sandbox tests exercise stale requests, unknown execution outcomes, and reconciliation. A failed callback alone does not free capacity.
Inspect the verification handoff ↗Dedicated multi-level verification of the contract includes Lean model proofs, bounded TLA+ checks, Kani on the Rust core, and conformance traces against the Rust core. The work targets v1.1.0, source revision 57b3f02. Verification found high-severity settlement/liveness findings F-1 and F-2. v1.1.0 fixes them and the lower-severity findings (findings).
Rust kernel, NEAR lock and synthetic executor, six deterministic scenarios, local Wasm integration tests, and a static explorer. The browser demo is a simulation or recorded replay—not a public-chain transaction.
Integrate into your systems, real payments, live LLM agents, or NEAR Intents integration. Note that this contract has been formally verified but has not been independently audited. Review the contract mechanics to adapt them to your use case.
Open source · MIT licensed · Built for the NEAR ecosystem
Modify the contract and policy for your application. Review the verification findings, connect your execution adapter, and deploy a gate your agents share.
Get the contract