Skip to content

Backend verification and contract security: On-chain market validation, error code snapshots, emergency drain constraints - #1505

Merged
Ehonrie merged 1 commit into
Netwalls:mainfrom
Joel234-png:batch-177-features
Oct 21, 2026
Merged

Ehonrie merged 1 commit into
Netwalls:mainfrom
Joel234-png:batch-177-features

Conversation

@Joel234-png

Copy link
Copy Markdown
Contributor

Closes #1367
Closes #1368
Closes #1402

… (#1402, #1368, #1367)

#1402 B-104: Verify POST /api/markets against the chain instead of trusting client fields

  • MarketVerificationService to validate markets exist on-chain before registration
  • Prevents users from registering fake market records that don't exist on-chain
  • Verifies contract address format (valid Stellar account)
  • Queries Soroban RPC to confirm market exists at provided contract
  • Validates client-provided metadata matches on-chain data
  • Rejects if client tries to override immutable chain data
  • Prevents creator spoofing by validating against authenticated user
  • Only indexer should create real market records via chain events

#1368 C-110: Snapshot-test ContractError discriminants shared with the frontend

  • Added comprehensive snapshot tests in errors.test.rs
  • Tests pin numeric error codes that frontend maps to error messages
  • Verifies all 23 error codes match snapshot (1, 2, 3, 10-15, 20-23, 30-32, 40-42, 50-52, 60)
  • Tests for uniqueness: no duplicate error codes
  • Tests for range integrity: proper organization by category with no overlaps
  • Failure message explicitly warns: "DO NOT CHANGE ERROR CODES - they are part of the contract API"
  • Documents that frontend/lib/errors.ts must be updated if codes change
  • Prevents silent frontend breakage from reordering or renumbering errors

#1367 C-109: Constrain Treasury::emergency_drain with timelock, events, and escrow protection

  • Implements 48-hour timelock before drain can execute
  • Prevents instant theft by requiring proposal → wait → execute pattern
  • Validates recipient against pre-approved emergency whitelist
  • Protects escrowed funds for open markets (cannot drain committed user funds)
  • Rate limiting: maximum 20% drain per 24-hour period
  • Comprehensive audit logging of all proposals and executions
  • Amount validation and re-checking before execution
  • Period-based rate limiting that resets every 24 hours
  • Cancel proposal function for admin control
  • Emits events for all drain operations for blockchain audit trail

…n, error code snapshots, emergency drain constraints (Netwalls#1402, Netwalls#1368, Netwalls#1367)

Netwalls#1402 B-104: Verify POST /api/markets against the chain instead of trusting client fields
- MarketVerificationService to validate markets exist on-chain before registration
- Prevents users from registering fake market records that don't exist on-chain
- Verifies contract address format (valid Stellar account)
- Queries Soroban RPC to confirm market exists at provided contract
- Validates client-provided metadata matches on-chain data
- Rejects if client tries to override immutable chain data
- Prevents creator spoofing by validating against authenticated user
- Only indexer should create real market records via chain events

Netwalls#1368 C-110: Snapshot-test ContractError discriminants shared with the frontend
- Added comprehensive snapshot tests in errors.test.rs
- Tests pin numeric error codes that frontend maps to error messages
- Verifies all 23 error codes match snapshot (1, 2, 3, 10-15, 20-23, 30-32, 40-42, 50-52, 60)
- Tests for uniqueness: no duplicate error codes
- Tests for range integrity: proper organization by category with no overlaps
- Failure message explicitly warns: "DO NOT CHANGE ERROR CODES - they are part of the contract API"
- Documents that frontend/lib/errors.ts must be updated if codes change
- Prevents silent frontend breakage from reordering or renumbering errors

Netwalls#1367 C-109: Constrain Treasury::emergency_drain with timelock, events, and escrow protection
- Implements 48-hour timelock before drain can execute
- Prevents instant theft by requiring proposal → wait → execute pattern
- Validates recipient against pre-approved emergency whitelist
- Protects escrowed funds for open markets (cannot drain committed user funds)
- Rate limiting: maximum 20% drain per 24-hour period
- Comprehensive audit logging of all proposals and executions
- Amount validation and re-checking before execution
- Period-based rate limiting that resets every 24 hours
- Cancel proposal function for admin control
- Emits events for all drain operations for blockchain audit trail
@Ehonrie
Ehonrie merged commit 13e1b39 into Netwalls:main Oct 21, 2026
3 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants