🎯 Objective
Add validation to prevent registration or pricing updates with negative or zero price_stroops values in the agent_registry Soroban contract. Currently, any i128 value is accepted.
📁 Files to Modify
| Action |
File Path |
Description |
| Modify |
smart-contracts/contracts/agent_registry/src/lib.rs |
Add price validation to register_agent, register_agents, and update_pricing |
📁 Reference Files
| File Path |
Purpose |
smart-contracts/contracts/agent_registry/src/lib.rs (line ~335) |
register_agent validation section |
smart-contracts/contracts/agent_registry/src/lib.rs (line ~395) |
register_agents batch validation |
smart-contracts/contracts/agent_registry/src/lib.rs (line ~479) |
update_pricing validation |
smart-contracts/contracts/agent_registry/src/lib.rs (Error enum) |
Existing error variants |
🔍 Current Vulnerable Code
register_agent (lib.rs ~line 335)
// CURRENT — No price validation
pub fn register_agent(env: Env, record: AgentParams) -> Result<(), Error> {
// Validates: not paused, not frozen, owner auth
// MISSING: price_stroops > 0 check
// ...
}
update_pricing (lib.rs ~line 479)
// CURRENT — No price validation
pub fn update_pricing(
env: Env,
agent_id: Symbol,
new_price: i128,
) -> Result<(), Error> {
// Validates: agent exists, not paused, not frozen, owner auth
// MISSING: new_price > 0 check
// ...
}
💥 Impact
- An agent could register with
price_stroops = -1000 (effectively paying users)
- The coordinator's cheapest-agent selection could be gamed
- Zero-price agents could flood the registry with free services
- Negative prices break economic assumptions in the payment layer
✅ Expected Fix
Add Error Variant (if not already present)
#[contracterror]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
#[repr(u32)]
pub enum Error {
NotFound = 1,
Unauthorized = 2,
AlreadyExists = 3,
ContractPaused = 4,
AgentFrozen = 5,
NotAdmin = 6,
AlreadyResolved = 7,
DuplicateInBatch = 8,
InvalidPrice = 9, // ADD THIS
}
Add Validation in register_agent
if record.price_stroops <= 0 {
return Err(Error::InvalidPrice);
}
Add Validation in update_pricing
if new_price <= 0 {
return Err(Error::InvalidPrice);
}
🧪 Tests to Add
#[test]
fn register_rejects_zero_price() {
// Register with price_stroops = 0 → should return Error::InvalidPrice
}
#[test]
fn register_rejects_negative_price() {
// Register with price_stroops = -100 → should return Error::InvalidPrice
}
#[test]
fn update_pricing_rejects_zero_price() {
// Update to price_stroops = 0 → should return Error::InvalidPrice
}
#[test]
fn update_pricing_rejects_negative_price() {
// Update to price_stroops = -50 → should return Error::InvalidPrice
}
✅ Acceptance Criteria
🎯 Objective
Add validation to prevent registration or pricing updates with negative or zero
price_stroopsvalues in theagent_registrySoroban contract. Currently, anyi128value is accepted.📁 Files to Modify
smart-contracts/contracts/agent_registry/src/lib.rsregister_agent,register_agents, andupdate_pricing📁 Reference Files
smart-contracts/contracts/agent_registry/src/lib.rs(line ~335)register_agentvalidation sectionsmart-contracts/contracts/agent_registry/src/lib.rs(line ~395)register_agentsbatch validationsmart-contracts/contracts/agent_registry/src/lib.rs(line ~479)update_pricingvalidationsmart-contracts/contracts/agent_registry/src/lib.rs(Error enum)🔍 Current Vulnerable Code
register_agent(lib.rs ~line 335)update_pricing(lib.rs ~line 479)💥 Impact
price_stroops = -1000(effectively paying users)✅ Expected Fix
Add Error Variant (if not already present)
Add Validation in
register_agentAdd Validation in
update_pricing🧪 Tests to Add
✅ Acceptance Criteria
InvalidPrice = 9variant to theErrorenum inlib.rsprice_stroops <= 0check inregister_agent→ returnError::InvalidPriceprice_stroops <= 0check inregister_agentsbatch validationnew_price <= 0check inupdate_pricing→ returnError::InvalidPricecargo test— all tests pass