Skip to content

feat(smart-contract): enforce metadata and storage size validation in agent-registry#133

Open
Opulencechuks wants to merge 16 commits into
Epta-Node:mainfrom
Opulencechuks:feature/agent-registry-size-limits
Open

feat(smart-contract): enforce metadata and storage size validation in agent-registry#133
Opulencechuks wants to merge 16 commits into
Epta-Node:mainfrom
Opulencechuks:feature/agent-registry-size-limits

Conversation

@Opulencechuks

Copy link
Copy Markdown
Contributor

Closes #115

Summary

The agent-registry contract previously allowed agents to store arbitrary metadata with no size limits. This vulnerability could allow a malicious or buggy agent to write unbounded data to persistent storage, consuming the contract's rent budget and increasing ledger costs for all users. This PR addresses the issue by defining maximum size constants and adding strict size validation on agent IDs, metadata entries, metadata value bytes, and total record storage size.

Changes

  • smart-contracts/contracts/agent_registry/src/lib.rs:
    • Defined maximum size constants (MAX_AGENT_ID = 64, MAX_METADATA_ENTRIES = 16, MAX_METADATA_VALUE_SIZE = 256, MAX_TOTAL_AGENT_STORAGE = 4096).
    • Updated AgentRecord to include metadata: Map<Symbol, Val> to store metadata entries.
    • Added typed contract error codes (AgentIdTooLong, TooManyMetadataEntries, MetadataValueTooLarge, StorageLimitExceeded) to the Error enum.
    • Implemented a private validate_record helper utilizing ToXdr serialization to calculate exact byte sizes.
    • Integrated validation inside register_agent().
    • Implemented update_agent(env: Env, record: AgentRecord) -> Result<(), Error> to support validated updates, including capability indexing updates if an agent changes capabilities.
    • Updated all existing unit tests to initialize the metadata map and added 7 new unit tests verifying limit validations.
  • smart-contracts/contracts/agent_registry/tests/integration.rs:
    • Updated the JSON payload for mock registration records to include "metadata":{}.

Testing

  • Added unit tests verifying successful registration with metadata (register_with_metadata_ok) and successful updates (update_agent_ok).
  • Added boundary test cases asserting typed error codes are returned on limit violations:
    • Too many metadata entries (validation_too_many_metadata_entries)
    • Oversized metadata values (validation_metadata_value_too_large)
    • Oversized total storage size (validation_total_storage_limit_exceeded)
  • Updated integration E2E mock payloads.

Related Issue

Smart-contract metadata and storage size bounds protection enhancement.

Checklist

  • Tests pass
  • Lint is clean
  • Documentation updated if needed

@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown

@Opulencechuks is attempting to deploy a commit to the Jaja's projects Team on Vercel.

A member of the Team first needs to authorize it.

@devJaja

devJaja commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Nice implementation @Opulencechuks
make the CI/smart contracts checks pass

@devJaja
devJaja self-requested a review July 20, 2026 22:40
@devJaja

devJaja commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@Opulencechuks
Resolve the conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Smart Contracts] Add Storage Size Limits Per-Agent to Prevent Unbounded Growth

2 participants