Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Agents submit an owner-defined recipe and exact integer quantity. The core check

## Hackathon review path

Submission details, category, team, and the matching formal verification are in [`nearhackathon.md`](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](docs/judges-guide.md) for a 90-second demo script and a claim-to-evidence map.

Start the lab below, then click **Begin docking sequence**. 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.
Expand Down
24 changes: 24 additions & 0 deletions nearhackathon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# NEAR Hackathon submission

This repository is a submission to the **November 2026 NEAR Hackathon**.

| | |
|---|---|
| **Category** | AI Security & Defense |
| **Project** | Shared Pool Controls: an MIT-licensed Rust / NEAR contract that keeps independent agents' combined commitments to a shared resource within an owner-defined policy |
| **Submission** | This repository, [difflabai/shared-pool-controls](https://github.com/difflabai/shared-pool-controls) |
| **Formal verification** | The matching verification work in [difflabai/formalver PR #31](https://github.com/difflabai/formalver/pull/31) |
| **Live site** | Static replay of the scenarios, published from this repository with GitHub Pages |

## What is submitted

- The Rust core, the NEAR lock contract, and the synthetic executor adapter in [`crates`](crates).
- Six scenarios (station power, GPU compute, delivery capacity, inventory, worker budgets, and risk headroom) with Rust-generated traces in [`scenarios`](scenarios).
- A static explorer and NEAR console in [`ui`](ui), plus a guide for configuring and deploying the contract against your own resource contention problem.
- Formal verification of the contract, in progress, in the companion PR above. It includes Lean model proofs and TLA+ checks; Rust-core Kani verification is pending and that PR reports settlement/liveness findings that are not yet resolved.

The [judge walkthrough](docs/judges-guide.md) has a 90-second demo script and a claim-to-evidence map. The contract is not independently audited and has not been deployed to a public network.

## Team membership

The hackathon rules allow a person to be a member of up to two teams. [gabehamilton](https://github.com/gabehamilton) is a member of the team for this submission and also a member of the team for the [gabehamilton/invest-in-near](https://github.com/gabehamilton/invest-in-near) submission.
2 changes: 1 addition & 1 deletion ui/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ guarded(reset);
const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
const revealAll = $('reveal-all');
if (!('IntersectionObserver' in window) || reducedMotion.matches) return;
const groups = document.querySelectorAll('.hero-copy, .orbital-scene, .premise-heading, .mechanism article, .energy-note, .section-heading, .demo-guide > div, .technical-points article, .evidence-grid article, .review-status > div, .near-boundary, .closing');
const groups = document.querySelectorAll('.hero-copy, .orbital-scene, .premise-heading, .mechanism article, .energy-note, .deploy-guide, .section-heading, .demo-guide > div, .technical-points article, .evidence-grid article, .review-status > div, .near-boundary, .closing');
const timers = new Map();
const clear = group => {
(timers.get(group) || []).forEach(clearTimeout);
Expand Down
22 changes: 22 additions & 0 deletions ui/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -1668,3 +1668,25 @@ body:not(.story-site) .row {
}

.orbital-scene { scroll-margin-top:16px; }

/* Deploy guide: configure and deploy the contract for your own problem. */
.deploy-guide { display:grid; grid-template-columns:1.1fr .9fr; gap:28px 56px; margin:56px 0 12px; padding-top:44px; border-top:1px solid var(--line); align-items:start; }
.deploy-intro { grid-column:1 / -1; max-width:720px; }
.deploy-intro h3 { font-size:clamp(1.5rem,2.6vw,2.1rem); line-height:1.2; margin:10px 0 14px; }
.deploy-intro p { color:var(--muted); font-size:.9rem; line-height:1.8; margin:0; }
.deploy-steps { list-style:none; margin:0; padding:0; display:grid; gap:2px; }
.deploy-steps li { display:flex; gap:22px; padding:20px 0; border-bottom:1px solid var(--line); }
.deploy-steps li:first-child { padding-top:4px; }
.deploy-steps li:last-child { border-bottom:0; }
.deploy-steps .step-number { font-size:1.6rem; margin:0; min-width:44px; }
.deploy-steps h4 { font-size:1rem; margin:0 0 8px; }
.deploy-steps p { font-size:.82rem; color:var(--muted); line-height:1.75; margin:0 0 8px; }
.deploy-steps code, .deploy-code + .deploy-commands code { font-size:.78em; }
.deploy-code { position:sticky; top:24px; }
.deploy-code pre { font-size:.7rem; line-height:1.75; white-space:pre; overflow-x:auto; }
.deploy-commands { grid-column:1 / -1; }
.deploy-commands pre { white-space:pre; overflow-x:auto; font-size:.74rem; line-height:1.8; }
@media(max-width:900px) {
.deploy-guide { grid-template-columns:1fr; gap:28px; }
.deploy-code { position:static; }
}
52 changes: 47 additions & 5 deletions ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,48 @@ <h1 id="hero-title">Three ships.<br>One power grid.<br><em>No exceptions.</em></
<span class="code-dim">// Reserve first. Dispatch second.</span>
commit(next);</code></pre><p>Recovery from an externally disturbed state has additional checks. See the full specification for exact semantics.</p></div>
<div class="technical-points"><article><span>01</span><div><h3>A pure Rust core</h3><p>Bounded data, checked integer arithmetic, fixed recipes. No NEAR dependency in the core’s default build.</p></div></article><article><span>02</span><div><h3>A NEAR execution boundary</h3><p>The synthetic adapter accepts execution only from the lock. Callback failure does not automatically release a commitment.</p></div></article><article><span>03</span><div><h3>A precise claim</h3><p>Accepted reservations do not increase the configured potential. External events can. Lean model proofs and TLA+ checks are complete; Rust-core verification remains in progress. <a href="https://github.com/difflabai/formalver/pull/31">Explore the formal verification.</a></p></div></article></div></div>
<div class="deploy-guide" id="deploy" aria-labelledby="deploy-title">
<div class="deploy-intro"><span class="eyebrow">Make it yours</span><h3 id="deploy-title">Configure it for your own contention problem. Deploy it on NEAR.</h3><p data-detail="1">Everything that makes the six scenarios different is data. Describe your shared resource in one JSON policy, then deploy the same tested Wasm.</p></div>
<ol class="deploy-steps">
<li><span class="step-number">01</span><div><h4>Name what is scarce.</h4><p data-detail="1">Each <code>metric</code> is a quantity the pool tracks, with hard <code>min</code> and <code>max</code> bounds: GPU blocks, MW, inventory, budget.</p><p data-detail="2">Add one metric per window or bucket you need to protect separately. A protected reserve is simply a lower <code>max</code> on the shared bucket.</p></div></li>
<li><span class="step-number">02</span><div><h4>Say what “worse” means.</h4><p data-detail="1">Each <code>term</code> scores imbalance: <code>Target</code> distance, <code>Excess</code> over a line, or <code>Deficit</code> below one. Admission requires the total never rises.</p><p data-detail="2">Weights decide which problems matter most. Hard bounds and the score are separate checks; a lower score never buys a breach.</p></div></li>
<li><span class="step-number">03</span><div><h4>Give each agent a recipe.</h4><p data-detail="1">A <code>recipe</code> fixes who may ask (<code>actor</code>), who executes (<code>executor</code>), what is reserved, and what completion changes. Agents choose only a recipe and a quantity.</p><p data-detail="2"><code>requires</code> chains recipes, so a later step can need an earlier one to finish first.</p></div></li>
<li><span class="step-number">04</span><div><h4>Build, deploy, initialize.</h4><p data-detail="1">Policy is immutable once <code>new</code> runs, so review it first. Deploy and initialize in one transaction from the contract’s own account.</p><p data-detail="2">Then check the code hash, preview as an agent, and submit.</p></div></li>
</ol>
<div class="code-panel deploy-code"><div class="code-header"><span>Shape of a policy</span><span>config.json</span></div><pre><code>{
"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": [] }]
}</code></pre></div>
<div class="deploy-commands">
<details><summary>Build and deploy commands <span aria-hidden="true">+</span></summary><div class="detail-body">
<pre><code># 1. Build both Wasm contracts and a provenance manifest
./scripts/build.sh

# 2. Deploy and initialize the lock in one transaction

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Document deployment and initialization of the configured executor

The command sequence deploys only pool_contract.wasm, even though the example policy binds every recipe to api-gateway.near. A fresh user following these steps has no initialized contract at that account which can accept execute/status; the first dispatch therefore fails, the lock records an unknown outcome, and the reservation cannot be released without authoritative executor evidence. The existing deployment preparation section requires deploying and initializing both contracts. Add an explicit adapter/executor deployment and initialization step (including its lock and operator configuration), or make the guide clearly require a pre-existing, initialized compatible adapter before the lock command.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1262842 (PR #5, since #3 had already merged): the command block now has a step that deploys and initializes the executor (new with lock and operator), notes that the bundled adapter is synthetic, and says a missing executor leaves the first dispatch Unknown with the reservation held.

# (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. Read it 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</code></pre>
<p>Use <a href="https://github.com/difflabai/shared-pool-controls/blob/main/docs/api.md#deployment-preparation">the deployment checklist</a> for account setup, then open <a href="live.html">the NEAR console</a> with your account and expected code hash.</p>
</div></details>
<details><summary>Before you deploy for real <span aria-hidden="true">+</span></summary><div class="detail-body"><p>Replace every <code>executor</code> 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 <code>execute</code> and <code>status</code> protocol, idempotency, and authoritative cancellation, and it must leave agents no route around the lock.</p><p>Policy and principals cannot be edited after initialization. A pool holds at most 32 metrics, 32 recipes, and 256 lifetime commitments; deploy a fresh pool to rotate. The contract is not independently audited and its formal verification is in progress, so test on testnet first.</p></div></details>
</div>
</div>
<div class="contract-details">
<details><summary>What exactly does an agent submit? <span aria-hidden="true">+</span></summary><div class="detail-body"><p>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.</p><pre><code>{
"recipe": 0,
Expand All @@ -128,19 +170,19 @@ <h1 id="hero-title">Three ships.<br>One power grid.<br><em>No exceptions.</em></
<details><summary>Inspect the selected scenario’s policy <span aria-hidden="true">+</span></summary><div class="detail-body"><pre id="policy"></pre></div></details>
<details><summary>Inspect the last Rust decision <span aria-hidden="true">+</span></summary><div class="detail-body"><pre id="raw">Run a scenario decision to inspect its response.</pre></div></details>
</div>
<div class="resource-links"><a href="https://github.com/difflabai/shared-pool-controls/blob/feat/shared-pool-controls/docs/spec.md"><span>Read the specification</span><span aria-hidden="true">↗</span></a><a href="https://github.com/difflabai/shared-pool-controls/tree/feat/shared-pool-controls/crates/core"><span>Explore the Rust core</span><span aria-hidden="true">↗</span></a><a href="live.html"><span>Open the NEAR console</span><span aria-hidden="true">↗</span></a></div>
<div class="resource-links"><a href="https://github.com/difflabai/shared-pool-controls/blob/main/docs/spec.md"><span>Read the specification</span><span aria-hidden="true">↗</span></a><a href="https://github.com/difflabai/shared-pool-controls/tree/feat/shared-pool-controls/crates/core"><span>Explore the Rust core</span><span aria-hidden="true">↗</span></a><a href="live.html"><span>Open the NEAR console</span><span aria-hidden="true">↗</span></a></div>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

Point the Rust core link at main

This resource link still targets feat/shared-pool-controls, while the surrounding links were changed to main and the PR intends to retire the old branch references. If that feature branch is deleted after merge, “Explore the Rust core” becomes a dead link. Replace the branch segment with main.

Suggested change
<div class="resource-links"><a href="https://github.com/difflabai/shared-pool-controls/blob/main/docs/spec.md"><span>Read the specification</span><span aria-hidden="true">↗</span></a><a href="https://github.com/difflabai/shared-pool-controls/tree/feat/shared-pool-controls/crates/core"><span>Explore the Rust core</span><span aria-hidden="true">↗</span></a><a href="live.html"><span>Open the NEAR console</span><span aria-hidden="true">↗</span></a></div>
<div class="resource-links"><a href="https://github.com/difflabai/shared-pool-controls/blob/main/docs/spec.md"><span>Read the specification</span><span aria-hidden="true">↗</span></a><a href="https://github.com/difflabai/shared-pool-controls/tree/main/crates/core"><span>Explore the Rust core</span><span aria-hidden="true">↗</span></a><a href="live.html"><span>Open the NEAR console</span><span aria-hidden="true">↗</span></a></div>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1262842 (PR #5): the Rust core link now points at main. No feat/shared-pool-controls references remain in the UI, README or docs.

</section>
<section class="evidence-section wrap" id="evidence" aria-labelledby="evidence-title">
<div class="section-kicker"><span>04 / Evidence for review</span><span>Run it. Inspect it. Check the boundary.</span></div>
<div class="section-heading"><h2 id="evidence-title">A visible decision.<br><em>A testable claim.</em></h2><p>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.</p></div>
<div class="evidence-grid">
<article><span class="eyebrow">Policy enforcement</span><h3>Reject the harmful commitment.</h3><p>The GPU trace includes a request that passes hard capacity bounds but raises energy. It is denied without reserving resources.</p><a href="https://github.com/difflabai/shared-pool-controls/blob/feat/shared-pool-controls/scenarios/gpu/trace.json">Inspect the Rust-generated trace ↗</a></article>
<article><span class="eyebrow">Execution authority</span><h3>Try going around the gate.</h3><p>NEAR sandbox tests attempt direct executor calls and agent-authored settlement. Both fail; registered execution evidence is required.</p><a href="https://github.com/difflabai/shared-pool-controls/blob/feat/shared-pool-controls/crates/sandbox/tests/integration.rs">Inspect the bypass tests ↗</a></article>
<article><span class="eyebrow">Asynchronous safety</span><h3>Keep uncertain work reserved.</h3><p>Sandbox tests exercise stale requests, unknown execution outcomes, and reconciliation. A failed callback alone does not free capacity.</p><a href="https://github.com/difflabai/shared-pool-controls/blob/feat/shared-pool-controls/docs/verification-handoff.md">Inspect the verification handoff ↗</a></article>
<article><span class="eyebrow">Policy enforcement</span><h3>Reject the harmful commitment.</h3><p>The GPU trace includes a request that passes hard capacity bounds but raises energy. It is denied without reserving resources.</p><a href="https://github.com/difflabai/shared-pool-controls/blob/main/scenarios/gpu/trace.json">Inspect the Rust-generated trace ↗</a></article>
<article><span class="eyebrow">Execution authority</span><h3>Try going around the gate.</h3><p>NEAR sandbox tests attempt direct executor calls and agent-authored settlement. Both fail; registered execution evidence is required.</p><a href="https://github.com/difflabai/shared-pool-controls/blob/main/crates/sandbox/tests/integration.rs">Inspect the bypass tests ↗</a></article>
<article><span class="eyebrow">Asynchronous safety</span><h3>Keep uncertain work reserved.</h3><p>Sandbox tests exercise stale requests, unknown execution outcomes, and reconciliation. A failed callback alone does not free capacity.</p><a href="https://github.com/difflabai/shared-pool-controls/blob/main/docs/verification-handoff.md">Inspect the verification handoff ↗</a></article>
</div>
<div class="near-boundary"><h3>Formal verification, with evidence you can inspect</h3><p>Dedicated verification of the contract includes Lean model proofs, bounded TLA+ checks, and conformance traces against the Rust core. The work targets source revision <code>a4bb5c3</code>. Kani verification of the Rust implementation remains pending; the PR reports high-severity settlement/liveness findings F-1 and F-2.</p><a href="https://github.com/difflabai/formalver/pull/31">Read the formal verification results, scope &amp; findings ↗</a></div>
<div class="review-status"><div><h3>What you can verify today</h3><p>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.</p></div><div><h3>Where the prototype stops</h3><p>No public-network deployment, real payments, live LLM agents, NEAR Intents integration, or production provider adapters. Not independently audited. Formal verification is in progress and has identified settlement/liveness findings. Policy quality and trusted observations remain assumptions.</p></div></div>
<div class="resource-links"><a href="https://github.com/difflabai/shared-pool-controls/blob/feat/shared-pool-controls/docs/judges-guide.md"><span>Reproduce the demo &amp; tests</span><span aria-hidden="true">↗</span></a><a href="https://github.com/difflabai/shared-pool-controls/actions"><span>Inspect CI runs</span><span aria-hidden="true">↗</span></a><a href="https://nearhackathon.com/"><span>Track: AI Security &amp; Defense</span><span aria-hidden="true">↗</span></a></div>
<div class="resource-links"><a href="https://github.com/difflabai/shared-pool-controls/blob/main/docs/judges-guide.md"><span>Reproduce the demo &amp; tests</span><span aria-hidden="true">↗</span></a><a href="https://github.com/difflabai/shared-pool-controls/actions"><span>Inspect CI runs</span><span aria-hidden="true">↗</span></a><a href="https://nearhackathon.com/"><span>Track: AI Security &amp; Defense</span><span aria-hidden="true">↗</span></a></div>
</section>
<section class="closing wrap"><p class="eyebrow">Open source · MIT licensed · Built for the NEAR ecosystem</p><h2>Your shared resources.<br><em>Your deployed contract.</em></h2><p>Modify the contract and policy for your application. Review the verification findings, connect your execution adapter, and deploy a gate your agents share.</p><a class="button primary" href="https://github.com/difflabai/shared-pool-controls">Get the contract <span aria-hidden="true">↗</span></a></section>
</main>
Expand Down
Loading