Skip to content

About

Control structures for shared resource pools

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Shared Pool Controls

Try the live site →

Shared Pool Controls: three ships, one power grid. Vega is told to wait to dock.

Independent agents. One shared limit. An MIT-licensed, open-source Rust / NEAR contract for commitments against a shared pool. Built for the AI Security & Defense track of NEAR Hackathon, it gives ecosystem developers a contract they can modify, configure, and deploy to address this class of shared-resource problems. Six scenarios use the same core and contract:

  1. Every ship wants to dock — station power, a protected life-support allocation, and an explicit wait before requesting a later window.
  2. Every team needs the GPU now — shared compute, protected inference capacity, smaller or later allocations.
  3. Everyone promised Friday — coupled machine and delivery reservations.
  4. Every branch hoards the scarce part — shared stock, protected depot reserve, receipt-gated availability.
  5. Every agent hires more agents — bounded worker funding, review earmarks, independent acceptance.
  6. Everyone is diversified—until they need the same exit — portfolio stress-loss budgets, collateral, fill-gated hedge credit.

Agents submit an owner-defined recipe and exact integer quantity. The core checks caller authority, freshness, prerequisites, resource bounds and V(after) <= V(before), then atomically reserves the commitment. The execution adapter accepts calls only from the lock. Unknown outcomes retain reservations.

Status: implemented prototype with Rust tests and NEAR sandbox integration tests. Not independently audited or deployed to a public network. This is v1.1.0. Formal verification of v1.1.0 (source revision 57b3f02) covers Lean model proofs, TLA+ checks, Kani on the Rust core, and conformance traces. Verification found settlement/liveness and other findings in v1.0.0; v1.1.0 fixes them (findings, changelog). Credits, GPU jobs, physical delivery, and financial positions are synthetic. The risk coefficients are illustrative, not a production portfolio model.

Hackathon review path

Submission details, category, team, and the matching formal verification are in nearhackathon.md.

Track: AI Security & Defense. The deliverable is an open-source contract that ecosystem teams can adapt and deploy for shared compute, delivery capacity, inventory, worker funding, and risk budgets. The explorer demonstrates those applications. See the judge walkthrough for a 90-second demo script and a claim-to-evidence map.

Start the lab below, then click Watch an example: docking. Atlas reserves 4 MW and Lyra 2 MW. Vega asks for 4 MW: WAIT TO DOCK. The station has 12 MW per window, but 4 MW is protected for life support; docking cannot exceed 8 MW. The denied request leaves 6 MW booked. Click Request Vega docking in window 02 to submit a fresh request against the second window. The animation reflects Rust decisions, not a JavaScript policy implementation. The original GPU scenario remains available as a separate example of an energy-only denial.

Run the interactive lab

Install Rust through rustup, Python 3, and optionally Node for JavaScript syntax checks. The repository selects Rust 1.98 and locks dependencies in Cargo.lock.

cargo run -p pool-demo -- serve
# Open http://127.0.0.1:8080

The site introduces the shared-resource problem, guides visitors into the six-scenario explorer, then opens up the contract specification, lifecycle and source code. Custom requests and evidence controls are available under expandable sections.

The server binds only to loopback. It serves plain HTML/CSS/JavaScript and evaluates decisions in Rust. There is no frontend build, package manager, database, private key, LLM, or external service requirement. Selecting identities and confirming completion are explicit simulator controls, not production authentication.

Use Run next decision to walk the trace; Preview and Submit exact quantity to explore; Suggest a smaller quantity to ask the bounded Rust planner for a suggestion. Unknown outcomes, confirmed nonexecution, duplicate completion, and a risk-market observation can be explored through the lifecycle controls.

The pages workflow publishes the UI and recorded traces to GitHub Pages on every push to main (enable it once under Settings → Pages → Source: GitHub Actions). The hosted site is a replay with manual submissions disabled.

For a completely static replay, serve the repository root with python3 -m http.server 8081, then open /ui/. The same page falls back to checked-in traces produced by Rust; manual submissions are disabled and the mode is clearly labeled. Generate them with:

cargo run -p pool-demo -- export
cargo run -p pool-demo -- trace risk

The separate ui/live.html is a static NEAR console: read any compatible deployed pool via RPC, preview an exact action, connect a wallet, and explicitly sign submission, dispatch, cancellation or reconciliation. It follows the trust-framework approval UI pattern: no held keys, text-only rendering of chain data, pinned wallet connector, explicit expected code hash before signing. No account is preselected. This signing path is implemented but not exercised against a public wallet/deployment by the automated suite.

Build and validate

./scripts/check.sh           # format, Rust tests, clippy, JS syntax
./scripts/build.sh           # both Wasm contracts and build provenance manifest
./scripts/sandbox.sh         # actual Wasm + asynchronous receipts in local NEAR
python3 scripts/smoke.py     # local HTTP demo; start server first

near-workspaces downloads its sandbox binary on first use. Network access and a supported host are required. build.sh builds with RUSTFLAGS="--cfg near" and fails if a Wasm does not import env.panic_utf8 (without the flag, failed calls carry no error name). It also fails if a Wasm imports a host function for an action other than a function call (deploy, keys, transfer, stake, accounts), or any import not on its reviewed list. artifacts/build.json records source revision, dirty status, Rust version, Rust flags, Cargo.lock hash, and each Wasm's hash and imports. This is a local build manifest, not an independent reproducibility or deployment attestation.

Small architecture

Component Responsibility
crates/core Dependency-free by default: bounded data, integer potential, admission, reservations and lifecycle
crates/contract NEAR identity, persisted state, events, promises and authenticated callbacks
crates/executor Enforced synthetic adapter, exact dispatch binding, independent operator, fault injection
crates/demo Rust local server, deterministic traces, bounded alternative search
crates/sandbox Wasm integration tests for all six configurations and uncertain outcomes
ui Static scenario lab and live NEAR console
scenarios Generated configurations and reproducible decision traces

One pool per deployment; immutable recipes, principals and policy. At most 32 metrics, 32 recipes and 64 potential terms. The pool keeps a window of the 256 most recent commitments. A new commitment prunes the oldest one if it is completed or cancelled; while the oldest is still open, submit fails Full, even if every other commitment has ended. The actor or owner can cancel the oldest while it is reserved; once dispatched, it closes only when its executor reports. So an executor that never reports can hold submit at Full. The synthetic executor forgets a job once the newest id the lock vouched for (by an execute that created a job, or by accepting a confirmation or finish) is 256 or more past its id; the lock has pruned that record by then. Honest use holds at most 256 jobs plus confirmations in flight, under a cap of 512. Confirmations the lock refuses (operator errors) keep their jobs, a typo of a far id for good; at least 256 of them above its newest id (more if fewer jobs sit at or below it) fill the cap and stop further confirmations, and if executions then keep failing that can hold submit at Full the same way (API). Ids keep counting, and a pruned id is NotFound; the event log keeps pruned records. Replay protection is the version, not retention. Prerequisites count completed units over the pool's whole life. Fixed limits bound computation and storage. The owner funds storage. The window replaces v1.0.0's 256 lifetime commitments (finding F-3); it is covered by tests and the v1.1.0 verification.

Read the API, state-machine specification, updated implementation plan, verification handoff, verification findings, and changelog.

Important boundaries

  • Hard bounds and the potential are different checks. A lower score cannot buy permission to breach a protected limit.
  • Pending commitments count immediately. Pending negative-risk hedge effects do not provide headroom before fill.
  • No unexecuted position backs a hedge: a hedge must stay in bounds if the position is later reported unexecuted.
  • Cancellation after dispatch needs authenticated evidence of nonexecution. A timeout or failed receipt is insufficient.
  • The administrator and registered execution/evidence accounts are trusted. The owner can update observed facts only when there are no unresolved commitments, and can restate the current values at any time to renew the snapshot; it cannot edit policy. That observation can raise energy or reveal a limit breach.
  • Only admitted reservation transitions promise nonincreasing energy. Settlement, cancellation, observations, fairness, economic correctness and eventual completion have separate assumptions.
  • The adapter boundary is real in the sandbox. Real brokers, cloud providers or warehouses would need enforceable integrations with no alternate credentials/path around the gate.
  • The prototype uses no real escrow token. Hiring credits are accounting fixtures, not NEAR balances.

The architecture follows difflabai/trust-framework: a pure core and thin wrapper. Its proofs do not apply to this code. Dedicated shared-pool formal verification targets v1.1.0, with the contract source pinned at 57b3f02: Lean proofs cover the model transcription, TLA+ checks a bounded model, Kani checks the Rust core, and conformance traces connect the models to the Rust core. Verification of v1.0.0 (pinned at a4bb5c3) reported high-severity settlement/liveness findings F-1 and F-2 (with F-2b), and lower-severity findings F-3 to F-6 and NT-F1 to NT-F4. v1.1.0 fixes all of them, F-4 only for a recipe whose actor is its executor (by the repository owner's decision, the owner may be a recipe's executor); see docs/verification-findings.md. The v1.1.0 verification checks those fixes. Changes to the contract or policy require review against the proof assumptions.

About

Control structures for shared resource pools

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages