Skip to content

Harden validate_invoice_id_string against fixed-buffer and charset edge cases #268

@mikewheeleer

Description

@mikewheeleer

Description

validate_invoice_id_string copies the invoice String into a fixed [0u8; 32] buffer and validates charset before converting to a Symbol. Audit the bounds handling (length 1..=MAX_INVOICE_ID_STRING_LEN, copy_into_slice, UTF-8 conversion) for any path that could read uninitialized bytes or accept an out-of-charset symbol, and add adversarial tests.

Requirements and context

  • Scoped to the LiquiFact escrow Soroban contract.
  • Test boundary lengths (0, 1, 32, 33), non-ASCII, and disallowed punctuation; assert each invalid input traps with the documented message.
  • Confirm only the first len bytes are validated and that no trailing zero byte from the buffer leaks into the Symbol.
  • Invariant: stored invoice symbol is always [A-Za-z0-9_], length 1..=32, and round-trips with off-chain slugs.
  • Reference docs/glossary.md and the module rustdoc on invoice identifiers.
  • Must be secure, tested, and documented.

Suggested execution

  • Fork the repo and create a branch:
    • git checkout -b security/invoice-id-validation
  • Implement changes:
    • escrow/src/lib.rs
    • Tests: escrow/src/tests/init.rs
    • Docs: docs/escrow-data-model.md
    • Include rustdoc/NatSpec-style doc comments on public functions
    • Validate security assumptions (auth, overflow, storage TTL, double-spend)

Test and commit

  • Run tests: cargo test
  • Cover edge cases (zero amounts, overflow, unauthorized callers, double-spend, state-machine misuse)
  • Include test output and security notes in the PR

Example commit message

test(escrow): adversarial invoice_id validation cases

Guidelines

  • Minimum 95% test coverage on new/changed code
  • Clear documentation
  • Timeframe: 96 hours from assignment

Metadata

Metadata

Assignees

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions