Architecture
How Bench is built — from source adapters to on-chain anchoring.
System Overview
┌─────────────────────────────────────────────────────────────────┐
│ Agent / Client │
│ POST /v1/certify │
└──────────────────────────┬──────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Attestor API (Hono) │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ Source Adapters (13) │ │
│ │ 1inch │ Paraswap │ KyberSwap │ OKX │ OpenOcean │ ... │ │
│ │ Parallel fan-out, normalized responses │ │
│ └──────────────────────────┬───────────────────────────────┘ │
│ │ │
│ ┌──────────────────────────▼───────────────────────────────┐ │
│ │ Consensus Engine │ │
│ │ Outlier removal → Weighted median → Agreement score │ │
│ └──────────────────────────┬───────────────────────────────┘ │
│ │ │
│ ┌──────────────────────────▼───────────────────────────────┐ │
│ │ Certificate Builder │ │
│ │ Canonical hash (sorted-key JSON) → EIP-712 signing │ │
│ └──────────────────────────┬───────────────────────────────┘ │
│ │ │
└──────────────────────────────┼──────────────────────────────────┘
│
┌────────────────┼────────────────┐
▼ ▼ ▼
┌──────────────────┐ ┌──────────────┐ ┌────────────────┐
│ PostgreSQL │ │ Redis │ │ BenchRegistry │
│ 7 tables │ │ quote cache │ │ X Layer (196) │
│ cert history │ │ TTL = 12s │ │ on-chain │
└──────────────────┘ └──────────────┘ └────────────────┘
Component Breakdown
@bench/sharedCore types, canonical hashing (sorted-key JSON, RFC 8785 subset), EIP-712 signing utilities, and BEC v2 constants. Zero external dependencies.
@bench/attestor13 source adapters, consensus engine, certificate builder, and Hono API server. Each adapter normalizes quotes to a standard format. The consensus engine computes weighted median, agreement scores, and certification levels.
@bench/contractsBenchRegistry.sol (Solidity 0.8.24) — on-chain certificate anchoring. Stores cert hashes with attestor address and timestamp. Supports single and batch anchoring.
@bench/dbPostgreSQL schema (7 tables) for certificate history, agent profiles, and aggregator performance. Redis layer for quote caching (12s TTL).
@bench/skillOKX Onchain OS plugin (BenchSkill SDK) — allows agents in the Onchain OS ecosystem to access Bench natively.
@usebench/verifierIndependent verification package. Zero internal dependencies — only uses ethers.js. Anyone can verify a certificate without trusting Bench infrastructure.
@bench/explorerNext.js 15 dashboard with 7+ routes. Displays live certificates, aggregator rankings, agent leaderboards, and comprehensive documentation.
Trust Model
Bench minimizes trust assumptions at every layer:
No single source is trusted. The weighted median of 13 independent sources provides the consensus price. Outliers are automatically removed.
Certificates are signed with EIP-712 typed data. The signature is verifiable by anyone with the attestor's public key. Tampering is detectable.
Certificate hashes use sorted-key JSON (RFC 8785 subset). Same input always produces the same hash — no ambiguity, no manipulation.
Once anchored to BenchRegistry, certificate records cannot be modified or deleted. X Layer provides the immutability guarantee.
@usebench/verifier has zero internal dependencies. It reconstructs the expected hash and recovers the signer — no Bench API calls needed.
Data Flow
- 1Agent sends POST /v1/certify with token pair, amount, and chain
- 2Attestor checks Redis cache for recent quotes (TTL 12s)
- 3If cache miss: fan out to all 13 adapters in parallel
- 4Each adapter normalizes its response to the standard SourceQuote format
- 5Consensus engine: outlier removal → weighted median → agreement scoring
- 6Certificate builder: canonical hash → EIP-712 sign → BEC v2 certificate
- 7Certificate stored in PostgreSQL, cache updated in Redis
- 8Certificate anchored to BenchRegistry on X Layer (async)
- 9Signed certificate returned to agent