Skip to content

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

Description

@devJaja

Problem

The agent-registry contract allows agents to store arbitrary metadata with no size limits. A malicious or buggy agent could write unbounded data to storage, consuming the contract's rent budget and increasing costs for all users.

Current State

Agent data stored in agent_registry includes metadata blobs with no size validation:

pub struct AgentData {
    pub agent_type: Symbol,
    pub metadata: Map<Symbol, Val>,  // unbounded!
    pub status: Symbol,
}

Proposed Solution

  1. Define maximum sizes:
    • MAX_AGENT_ID: usize = 64
    • MAX_METADATA_ENTRIES: usize = 16
    • MAX_METADATA_VALUE_SIZE: usize = 256 (bytes)
    • MAX_TOTAL_AGENT_STORAGE: usize = 4096 (bytes)
  2. Add validation in register_agent() and update_agent():
    • Check symbol lengths
    • Check metadata map size
    • Check total serialized size
  3. Return typed errors for size violations
  4. Add tests for boundary conditions

Acceptance Criteria

  • Size constants defined
  • Validation rejects oversized agent IDs
  • Validation rejects too many metadata entries
  • Validation rejects oversized metadata values
  • Total agent storage bounded
  • Tests verify rejection at each boundary
  • Error messages indicate which limit was exceeded

Difficulty

Medium — validation logic only, no storage layout changes

Labels

smart-contract stellar enhancement

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions