Introduce a hard limit on Milestone.title length in contracts/accountability_vault to prevent unbounded storage growth and excessive ledger fees caused by oversized string inputs.
This ensures predictable storage costs and improves contract safety and accountability.
-
Introduce a constant:
pub const MAX_TITLE_LEN: usize = 128;
-
Validate
Milestone.titleinsidecreate_vaultbefore vault creation logic executes. -
Enforce byte-length validation (not character count) using
String::len()semantics as defined bysoroban_sdk::String. -
Reject any title where:
title.len() > MAX_TITLE_LEN
-
Add a new error variant to the contract error enum:
TitleTooLong
-
Alternatively (if error catalog constraints apply), evaluate reuse of
InvalidAmountonly if semantically acceptable; prefer explicit error for clarity. -
Ensure error is returned early and consistently before any storage writes occur.
Add boundary and regression tests:
-
Valid case:
- Title length exactly
MAX_TITLE_LENshould succeed.
- Title length exactly
-
Invalid case:
- Title length
MAX_TITLE_LEN + 1should returnTitleTooLong.
- Title length
-
Edge cases:
- Empty title (if allowed by existing logic).
- Multi-byte UTF-8 characters to confirm byte-length enforcement.
-
Ensure no partial state is written on rejection.
- ≥95% test coverage for modified contract paths.
Include:
- Description of
MAX_TITLE_LEN - Rationale: storage cost control and ledger fee protection
- Behavior on validation failure
- Error returned (
TitleTooLong) - Example valid vs invalid input
- Prevents unbounded ledger bloat via oversized metadata fields.
- Ensures predictable storage fees per vault creation.
- Eliminates potential DoS vectors through large string submissions.
-
Fork repository and create branch:
git checkout -b bug/milestone-title-length-bound
-
Implement contract changes:
- Add
MAX_TITLE_LEN - Add validation in
create_vault - Add error variant
- Add
-
Add tests in
test.rs -
Update
README.md -
Run full test suite:
cargo test -
Verify:
- Boundary conditions pass
- Over-limit titles fail correctly
- No regression in vault creation logic
fix: bound milestone title length in create_vault
Vault creation enforces strict title size limits, preventing excessive storage usage and ensuring predictable on-chain costs while maintaining backward-compatible behavior for valid inputs.