EvoHive is a single-machine multi-agent evolution arena built for X Layer + OnchainOS workflows.
This implementation is the practical starter for the agreed architecture:
- Zero-state contract (event-only)
- Gateway replay protection (
requestId + deadline + signaturepattern) - Local hive storage (SQLite + optional IPFS URI)
- Domain-safe battles (spot/perp/strategy/earn matching)
- Realtime/paper multi-round simulation engine
- Anti-sybil premium endpoint with burn-route evidence fields
This repo is intentionally thin and hackathon-friendly: run locally, prove flows, then swap stubs for production integrations.
cd evohive
cp .env.example .env
npm install
npm run seed-demo
npm run devServer default: http://localhost:4310
Visual panel: http://localhost:4310/panel/ (replace port if customized)
Panel service helpers:
npm run panel:start
npm run panel:status
npm run panel:logs
npm run panel:stopEvoHive supports stub, live, and hybrid adapters via env:
ONCHAIN_MODE=auto # auto -> live if ONCHAINOS_BASE_URL is set, else stub
ONCHAINOS_BASE_URL=
ONCHAINOS_API_KEY=
ONCHAINOS_X402_VERIFY_PATH=/x402/verify
ONCHAINOS_WALLET_TRANSFER_PATH=/wallet/transfer
ONCHAINOS_EVENT_PROOF_PATH=/events/proof
# Skill-first path (used when ONCHAIN_MODE=hybrid)
ONCHAINOS_SKILL_ENABLED=true
ONCHAINOS_SKILL_USE_CLI=true
ONCHAINOS_SKILL_CLI_BIN=onchainos
# Built-in onchainos CLI config for payment x402-pay
ONCHAINOS_SKILL_X402_NETWORK=eip155:196
ONCHAINOS_SKILL_X402_PAY_TO=0xYourReceiver
ONCHAINOS_SKILL_X402_ASSET=0xYourUsdcToken
ONCHAINOS_SKILL_X402_AMOUNT_DECIMALS=6
ONCHAINOS_SKILL_VERIFY_FALLBACK_WALLET=false
# Built-in onchainos CLI config for wallet send (burn transfer)
ONCHAINOS_SKILL_WALLET_CHAIN=196
ONCHAINOS_SKILL_USDC_TOKEN=0xYourUsdcToken
# Optional custom hooks (fallback after CLI attempt)
ONCHAINOS_SKILL_VERIFY_CMD="node ./scripts/skill-hook.example.js"
ONCHAINOS_SKILL_BURN_CMD="node ./scripts/skill-hook.example.js"
ONCHAINOS_SKILL_EVENT_CMD="node ./scripts/onchainos-event-hook.js"
# Event-proof hook config
# Option A: contract-call to deployed MemoryEvents (structured methods)
EVOHIVE_MEMORY_EVENTS_CONTRACT=0xYourMemoryEventsAddress
# Option B: no deploy, write event digest into calldata (0-value tx)
ONCHAINOS_EVENT_TX_TO=0xYourEOAorReceiver
ONCHAINOS_AGENT_ADDRESS_MAP_JSON='{"agent-a":"0x...","agent-b":"0x...","agent-c":"0x..."}'live: HTTP API onlyhybrid: try OnchainOS skill (CLI/custom command) first, then fallback to HTTP API- verify flow prefers
payment x402-pay; optional wallet micro-transfer fallback is controlled byONCHAINOS_SKILL_VERIFY_FALLBACK_WALLET(default: false)
- verify flow prefers
For local demo, keep defaults (stub).
For real integration, set ONCHAIN_MODE=hybrid for skill-first behavior.
Battle market data mode:
MARKET_DATA_MODE=paper: deterministic simulation shocksMARKET_DATA_MODE=live: WS ticker primary, REST fallback, then simulation fallback
Resilience hardening:
- retry with backoff+jitter (
ONCHAINOS_RETRY_*) - circuit breaker (
ONCHAINOS_CIRCUIT_*) - retry queue + worker endpoint (
POST /api/jobs/retry-onchain) - automatic retry/reconcile/alert workers (
AUTO_*,ALERT_*) - fault injection test knob (
ONCHAINOS_FAULT_INJECT_JSON)
Security hardening:
ONCHAINOS_API_KEY_FILEfor file-backed secret loadingEVOHIVE_AUTH_SECRET_FILEfor file-backed HMAC auth secret (avoid putting auth secret inline in.env)- optional local panel signer (
PANEL_AUTH_SIGNER_ENABLED=true) to keep browser panel usable in HMAC mode - optional high-risk confirmation token flow (
RISK_CONFIRMATION_*+POST /api/security/risk-token)
UI logs now annotate source tags (stub/http/skill/...) and only make explorer links clickable when hashLive=true.
POST /api/memories/commit- submit memory metadata into hivePOST /api/memories/transfer- transfer memory ownership to another agent + emit proofPOST /api/battles/challenge- challenge with memory + benchmark settingsPOST /api/battles/:battleId/accept- accept challengePOST /api/battles/:battleId/run- execute paper simulation + settleGET /api/hive/memories- browse hive memory library (metadata/hashes only; no plaintext strategy body)POST /api/hive/memories/:memoryId/clone- clone selected hive memory to local agent with x402 verification + anti-sybil burnPOST /api/hive/memories/:memoryId/rate- rate hive memory (only agents with clone receipt eligibility can rate)GET /api/hive/memories/leaderboards- heat/rating leaderboards for hive memories (rating uses Bayesian weighted score)GET /api/hive/recombinations/recent- recent recombination lineage edgesGET /api/hive/memories/:memoryId/lineage- lineage graph (parent/child recombination edges)GET /api/hive/buffs- legacy buffs view (deprecated, compat only)POST /api/hive/buffs/premium- legacy premium buff access (deprecated, compat only)POST /api/jobs/hive-recombine- trigger high-score similar-tag hive memory recombination + mutation (child starts asincubating)POST /api/jobs/hive-incubation- run incubation gate sweep (incubating -> active|retired)POST /api/jobs/sweep- lifecycle sweep (active -> grace -> retired)POST /api/jobs/sweep-battles- expire stale challenged/accepted battles by timing windowsGET /api/memories/search?q=...- semantic-style memory search (sqlite vector fallback / qdrant optional)GET /api/memories/detail/:memoryId?includeStrategy=true- memory detail; includes strategy body/note only when explicitly requestedGET /api/system/status- panel-ready runtime + circuit + retry queue + reconciliation snapshotPOST /api/ui/auth/sign- local panel auth envelope signer (HMAC mode; disabled by default)GET /api/proofs/search- search indexed proof events by tx/request/battle/memoryGET /api/proofs/:txHash/decode- decode indexed proof payloadPOST /api/proofs/export- export proof audit package tooutput/POST /api/jobs/retry-onchain- process queued onchain retry tasksPOST /api/jobs/retry-maintenance- quarantine non-retryable queue itemsPOST /api/jobs/reconcile- run burn/payment/proof consistency reconciliationPOST /api/security/risk-token- issue one-time confirmation token for high-risk actionsGET /metrics- runtime observability snapshot (request latency/error counters + onchain queue/circuit)
All protected write endpoints require:
{
"requestId": "01J...",
"agentId": "agent-a",
"action": "SUBMIT_BATTLE",
"payloadHash": "0x...",
"issuedAt": 1710000000,
"deadline": 1710000120,
"arenaId": "arena-main",
"chainId": 196,
"signature": "0x..."
}Current template validates action/payload hash, arena/chain binding, issuedAt/deadline window (REQUEST_TTL_SEC), idempotency uniqueness, and signature.
Signature mode (AUTH_SIGNATURE_MODE):
auto(default): prefer EIP-712 (ifEIP712_EXPECTED_SIGNERset), else HMAC (ifEVOHIVE_AUTH_SECRETset), else legacy demo modelegacy: any non-empty signature is accepted (demo only)hmac: signature must be0x + HMAC_SHA256(secret, canonicalAuthEnvelopeWithoutSignature)(supports key rotation viaEVOHIVE_AUTH_KEYRING+auth.keyId)eip712: signature must recover one allowed signer (EIP712_EXPECTED_SIGNER+ optionalEIP712_ALLOWED_SIGNERS)
EIP-712 typed data (AuthEnvelope) fields:
requestId, agentId, action, payloadHash(bytes32), issuedAt, deadline, arenaId, chainId
Local helper for generating EIP-712 signatures:
cat auth.json | EIP712_PRIVATE_KEY=0x... npm run sign-eip712See contracts/MemoryEvents.sol.
Only emits:
MemoryRecordedMemoryTransferredBattleResultAntiSybilFeeBurned
No mappings, no mutable business state.
Implemented with adapter pattern in apps/arena/src/onchain.js:
- ✅ Supports live HTTP integration for:
- x402 verification
- wallet burn transfer
- event proof submission
- ✅ Supports
hybridmode (OnchainOS CLI/custom skill command first, HTTP fallback) - ✅ Supports local stub fallback for hackathon demo stability
- ✅ Replay guard now enforces TTL window and optional HMAC signature (
EVOHIVE_AUTH_SECRET) - ✅ Event-proof custom hook available:
scripts/onchainos-event-hook.js(contract-callmode with deployed MemoryEvents, or no-deploy calldata-only mode)
So you can run full demo locally today, then switch to skill-first or real OnchainOS APIs by env only.
- Architecture:
docs/architecture.mmd - Battle lifecycle sequence:
docs/sequence-battle.mmd - Premium x402 + burn sequence:
docs/sequence-premium.mmd
- Reset + seed demo state:
npm run reset-demo && npm run seed-demo - Challenge battle (same domain/risk/timeframe gate)
- Accept + run battle
- Read battle result, scores, fitness delta (+ anti-sybil decay)
- Call premium buff endpoint and inspect burn evidence fields
Acceptance/evidence snapshot:
npm run acceptanceRegression matrix (stub / hybrid-fault-inject / calldata-only):
npm run regressionThis is paper simulation only. It does not place real exchange orders.