Cortex

Security

Threat model and security analysis for Cortex as a Base-native agentic commerce protocol. Covers protocol, policy, commerce, and offchain service risks.

1. Base / L2 Dependency Risks

ThreatSeverityMitigation
Bridge exploit (token drain)CriticalPrefer native Base assets and canonical bridges. Monitor bridge and stablecoin issuer risk.
Sequencer censorshipHighBase inherits OP Stack forced inclusion paths. Agents and merchants should retry or use alternate rails when degraded.
Sequencer liveness failureHighDocument operational fallback and pause guidance for services that need timely settlement.
Data availability gapMediumL1 calldata/blobs ensure state reconstructability.
Public RPC range limitsMediumIndexer chunks log polling below Base Sepolia RPC limits and checkpoints progress.

2. Intent Manipulation / Replay

ThreatSeverityMitigation
Intent replay (same chain)HighPer-owner nonce mapping. Once used, permanently consumed.
Intent replay (cross-chain)MediumEIP-712 domain includes chainId and verifyingContract.
Intent forgery (wrong signer)HighEIP-712 signature verification via ECDSA.recover.
Intent front-runningMediumMVP accepts this; future: encrypted mempools or commit-reveal.
Expired intent fillLowfillIntent() checks block.timestamp >= deadline and reverts.
Constraint violationLowfillIntent() enforces amountIn <= amountInMax and amountOut >= amountOutMin.

Invariants verified by fuzz/invariant tests:

  • invariant_noDoubleFill — no intent can be filled twice
  • invariant_nonceReplayProtection — nonce replay always reverts
  • invariant_statusConsistency — filled + cancelled <= submitted

3. Solver Censorship or Abuse

ThreatSeverityMitigation
Solver censorshipMediumPermissionless solver registration and indexed fill quality reduce reliance on one solver.
Solver MEV extractionMediumConstraint enforcement on-chain (amountInMax/amountOutMin).
Solver griefingLowFill constraints checked on-chain. Invalid fills revert.
Solver downtimeMediumIntents remain OPEN until deadline. Agents can cancel and resubmit.

4. Policy Bypass Patterns

ThreatSeverityMitigation
delegatecall to untrusted contractHighPolicyAccount restricts execution to call only.
approve + transferFrom bypassMediumERC-20 transfer, approve, and transferFrom calldata is detected and charged against token limits.
Spend limit race (multi-tx)LowrecordSpend() uses storage-level cumulative tracking.
Rolling window manipulationLowWindow resets after 24h. Cannot be shortened by the account.
Target allowlist bypass via proxyMediumAllowlist checks direct target address.
Function selector collisionLow4-byte selectors practically safe for known interfaces.
Signed payment replayHighSigned payment recording enforces merchant/token/facilitator budgets and payment-hash replay protection.

Invariants verified by fuzz/invariant tests:

  • invariant_spentNeverExceedsPeakMax — spentToday never exceeds peak maxPerDay
  • invariant_windowResetClearsSpend — window reset clears spending correctly
  • invariant_perTokenIsolation — per-token spending is isolated

5. Key Management

ThreatSeverityMitigation
Agent key compromiseCriticalPolicyModule caps daily spending. Target allowlist limits destinations. Owner can revoke.
Solver key compromiseHighSolver can only fill intents within constraints.
Deployer key compromiseHighContracts are immutable once deployed. Deployer not privileged.
Key rotationMediumAgentRegistry supports updateAgent. Policies are reconfigurable.

6. Smart Contract Risks

ThreatSeverityMitigation
ReentrancyLowNo external calls before state changes. Checks-effects-interactions.
Integer overflowLowSolidity 0.8.24 built-in overflow checks.
Storage collisionLowNo upgradeable proxies in MVP.
Uninitialized stateLowAll mappings default to zero/false.

7. Commerce Risks

ThreatSeverityMitigation
Fake merchant or cloned serviceHighMerchant, service, and facilitator records are anchored onchain with metadata hashes.
Quote replayHighQuote hashes bind chain ID, registry address, merchant, service, agent, token, rail, nonce, terms, resource, x402 payload, and fees.
Payment payload substitutionHighx402 payloads bind through x402PayloadHash; other rails bind through terms/resource hashes plus account policy.
Merchant non-fulfillmentMediumReceipts, fulfillment hashes, disputes, and trust signals create a shared risk trail.
Refund abuse by agentsMediumDispute and trust-signal history is indexed for agents and merchants.
Privacy leakage in metadataMediumKeep sensitive prompts, URLs, payloads, and business intent out of public metadata.

8. Offchain Service Risks

ThreatSeverityMitigation
Indexer data desyncMediumTracks lastProcessedBlock. Resumes from checkpoint.
API injection (SQL)HighAll queries use parameterized statements ($1, $2).
API denial of serviceMediumPagination limits (max 100). No unbounded queries.
Database corruptionMediumPostgres WAL + standard backup. Idempotent migrations.
Hosted API outageMediumOnchain state remains canonical; agents can fall back to direct RPC/log reads or alternate indexers.

Static Analysis

  • Slither runs in CI to detect common vulnerability patterns.
  • Solhint enforces Solidity coding standards.
  • Forge fmt ensures consistent formatting.
  • Fuzz tests run 1,000 iterations per property.
  • Invariant tests run 256 sequences of 64 calls each.