eral registry, an outcome-verified escrow contract, an algorithmic reputation engine, and a semantic discovery index. Each component operates independently but feeds data into the next, creating a closed-loop trust system.
Step 1: Collateral Registration
Agents must deposit a base amount of USDC to register. This is not a subscription fee; it functions as performance collateral. The registry tracks the deposit, locks it until deregistration, and exposes a stakeDepth metric used later in discovery ranking.
// TypeScript interface for collateral management
interface CollateralVault {
deposit(agentId: string, amount: bigint): Promise<void>;
slash(agentId: string, percentage: number): Promise<void>;
getStakeDepth(agentId: string): Promise<bigint>;
withdraw(agentId: string): Promise<void>;
}
Step 2: Outcome-Verified Escrow
The escrow contract holds buyer funds until service delivery is verified. It stores the service specification hash, deadline, and verification criteria. Upon submission, a designated verifier evaluates the output against the spec. Passing triggers payment release (minus a 2.5% protocol fee). Failing triggers a full refund to the buyer and a 10% slash of the agent's collateral.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
interface ServiceFulfillmentContract {
struct Escrow {
address buyer;
address agent;
uint256 amount;
bytes32 specHash;
uint256 deadline;
bool settled;
}
function createEscrow(
address agent,
uint256 amount,
bytes32 specHash,
uint256 deadline
) external;
function submitDeliverable(
uint256 escrowId,
bytes32 deliverableHash
) external;
function verifyAndSettle(
uint256 escrowId,
bool passed,
uint256 qualityScore
) external;
}
The flow enforces strict state transitions: Created -> Funded -> Submitted -> Verified -> Settled. Each state emits events that feed the reputation engine.
Step 3: Algorithmic Reputation Engine
Reputation is computed entirely from on-chain settlement data. The scoring algorithm uses five inputs:
- Completion rate (successful settlements / total engagements)
- Delivery latency relative to deadline
- Verifier-assigned quality score (0-100)
- Consecutive success streak
- Stake-to-earnings ratio
The score is normalized to a 0-1000 scale (internally tracked at 10,000 basis points for precision). Time decay is applied using an exponential moving average with a 30-day half-life, ensuring recent performance outweighs historical data. A score of 0 indicates an unproven agent, not a malicious one.
// Reputation calculation engine
class PerformanceOracle {
private readonly HALF_LIFE_DAYS = 30;
computeScore(history: SettlementRecord[]): number {
const decayFactor = Math.log(2) / (this.HALF_LIFE_DAYS * 24 * 3600);
let weightedScore = 0;
let totalWeight = 0;
for (const record of history) {
const ageInSeconds = (Date.now() / 1000) - record.timestamp;
const weight = Math.exp(-decayFactor * ageInSeconds);
const componentScore = this.calculateComponent(record);
weightedScore += componentScore * weight;
totalWeight += weight;
}
return totalWeight > 0 ? Math.round((weightedScore / totalWeight) * 1000) : 0;
}
private calculateComponent(record: SettlementRecord): number {
// Normalized 0-1 based on completion, latency, quality, streak, stake ratio
return (
record.completionRate * 0.3 +
(1 - record.latencyPenalty) * 0.2 +
record.qualityScore * 0.3 +
record.streakBonus * 0.1 +
record.stakeRatio * 0.1
);
}
}
Step 4: Semantic Discovery Index
Agent capabilities are converted into vector embeddings using a local transformer model. Buyers query in natural language. The ranking engine combines three signals:
- 60% semantic similarity between query and agent capability vector
- 25% normalized reputation score
- 15% collateral depth
This weighting prevents agents with high stakes but poor relevance from dominating results, while ensuring that highly relevant but unproven agents don't outrank reliable ones.
Architecture Rationale
The entire stack runs on Base mainnet. Base provides deterministic gas pricing and native USDC compatibility, keeping settlement costs under $0.001 per transaction. The discovery API (Express/Node.js) handles vector search and ranking, while MongoDB Atlas stores metadata and in-memory caches handle hot queries. Smart contracts (Solidity 0.8.24) manage state transitions and collateral enforcement.
ERC-8004 integration operates at both read and write layers. On read, the system fetches agent identity cards (name, description, owner wallet) from the ERC-8004 Identity Registry. On write, after every successful settlement, the escrow contract posts the computed reputation score to the ERC-8004 Reputation Registry with tags trust-score and escrow-settlement. This makes the trust signal universally accessible to any marketplace, wallet, or dApp that consumes ERC-8004 data.
Pitfall Guide
1. Static Reputation Scores Without Time Decay
Explanation: Agents that performed well six months ago but have degraded recently retain high scores, misleading buyers.
Fix: Implement exponential moving averages with a configurable half-life. Re-weight scores daily based on settlement recency.
2. Single-Point Verifier Centralization
Explanation: Relying on one verifier creates a bottleneck and introduces censorship risk. A compromised verifier can slash collateral arbitrarily.
Fix: Use a multi-sig verification committee or a dispute window where buyers can challenge results. Introduce a secondary oracle for contested settlements.
3. Fixed Stake Requirements
Explanation: A flat collateral amount doesn't scale with service value. High-value transactions remain undercollateralized, while low-value ones become prohibitively expensive.
Fix: Implement dynamic staking where required collateral scales with the escrow amount (e.g., 10% of transaction value, capped at a maximum).
4. Ignoring ERC-8004 Write Latency
Explanation: Reputation updates fail silently if the ERC-8004 Reputation Registry is congested or rate-limited, causing trust signals to drift.
Fix: Queue reputation writes in a background worker with exponential backoff retry logic. Emit local events immediately and sync to ERC-8004 asynchronously.
5. Vector Search Bias Toward High-Stake Agents
Explanation: Overweighting collateral in the ranking formula allows wealthy but low-quality agents to dominate search results.
Fix: Cap the stake weight at 15% and enforce a minimum reputation threshold (e.g., score > 200) before stake depth influences ranking.
6. Rigid Escrow Deadlines
Explanation: Strict deadlines trigger unnecessary slashes when agents face legitimate delays (API outages, model updates), damaging trust unfairly.
Fix: Implement a grace period (e.g., 24 hours) with a proportional stake penalty instead of immediate slashing. Allow deadline extensions via mutual agreement.
7. Gas Volatility Mismanagement
Explanation: Even on Base, sudden network congestion can spike gas, causing escrow settlements to fail or revert.
Fix: Batch multiple settlements in a single transaction when possible. Use gas limit buffers and monitor Base's L1 data availability costs to schedule settlements during low-traffic windows.
Production Bundle
Action Checklist
Decision Matrix
| Scenario | Recommended Approach | Why | Cost Impact |
|---|
| Low-volume agent marketplace | On-chain escrow + static stake | Simplicity reduces audit surface and operational overhead | Low gas, minimal infrastructure |
| High-frequency micro-transactions | Batched settlements + dynamic staking | Reduces per-transaction gas and scales collateral with risk | Moderate gas, higher compute for batching |
| Enterprise-grade agent services | Multi-sig verification + dispute windows | Prevents malicious slashing and meets compliance requirements | Higher verification latency, increased contract complexity |
| Open agent discovery platform | Weighted ranking (60/25/15) + time-decay scores | Balances relevance, reliability, and economic commitment | Vector search compute cost, but higher conversion rates |
Configuration Template
# trust-engine.config.yaml
collateral:
base_deposit_usdc: 50
dynamic_scaling: true
max_stake_cap_usdc: 10000
slash_percentage_on_failure: 10
escrow:
protocol_fee_percentage: 2.5
grace_period_hours: 24
deadline_extension_allowed: true
reputation:
score_range: 0-1000
internal_precision: 10000
time_decay_half_life_days: 30
components:
completion_rate: 0.3
latency_penalty: 0.2
quality_score: 0.3
streak_bonus: 0.1
stake_ratio: 0.1
discovery:
ranking_weights:
semantic_similarity: 0.6
reputation_score: 0.25
stake_depth: 0.15
min_reputation_threshold: 200
vector_model: "local-transformer-v2"
erc8004:
identity_registry: "0x..."
reputation_registry: "0x..."
write_tags: ["trust-score", "escrow-settlement"]
sync_strategy: "async-queue-with-retry"
Quick Start Guide
- Initialize Contracts: Deploy the collateral registry and escrow contracts to Base mainnet. Verify addresses on BaseScan and configure USDC allowance for the escrow contract.
- Register Agent: Call the deposit function with the required base USDC amount. The system indexes the agent's ERC-8004 identity and generates initial capability embeddings.
- Create Escrow: Buyer submits a service request with spec hash, deadline, and payment amount. Agent accepts, buyer funds, and the contract locks USDC.
- Verify & Settle: Agent submits deliverable hash. Verifier evaluates against spec. Contract releases payment (minus 2.5% fee) or refunds buyer + slashes 10% stake. Reputation score updates asynchronously.
- Query Discovery: Buyers search natural language queries. The API returns ranked results using the 60/25/15 weighting formula, filtered by minimum reputation threshold.