Skip to content

Fix: 4 issues (#1839, #1840, #1841, #1842) - #1992

Open
ochayamary20 wants to merge 1 commit into
solutions-plug:mainfrom
ochayamary20:simple/1839-1840-1841-1842
Open

ochayamary20 wants to merge 1 commit into
solutions-plug:mainfrom
ochayamary20:simple/1839-1840-1841-1842

Conversation

@ochayamary20

Copy link
Copy Markdown

Closes #1839
Closes #1840
Closes #1841
Closes #1842

Issues

#1839 Add a cfg(test) gate around contract test modules in lib.rs

Summary

contracts/predict-iq/src/lib.rs declares the many test modules (test.rs, query_tests.rs, test_cancellation.rs, modules/*_test.rs and others) without a #[cfg(test)] gate, so they are compiled into the main crate. This bloats release builds and can leak test-only helpers into production artifacts.

Motivation

Compiling test modules into the shipped contract increases WASM size and gas-relevant code surface, and risks test-only code paths being reachable. Closed issue #‍1716 already identified this exact gap, so the fix is well understood and low risk.

Proposed solution

Scope & Acceptance Criteria

  • Wrap every test-only module declaration in contracts/predict-iq/src/lib.rs with #[cfg(test)]
  • Confirm modules/mod.rs test submodules are likewise gated
  • Verify cargo build (non-test) no longer compiles the test modules and cargo test still passes
  • Out of scope: Refactoring the contents of individual test modules
  • Out of scope: Changing the fuzz targets under contracts/predict-iq/fuzz

Implementation Guidelines

  • Follow the existing module declaration style in contracts/predict-iq/src/lib.rs and contracts/predict-iq/src/modules/mod.rs
  • Use #[cfg(test)] on each test module declaration rather than a single catch-all where modules are interleaved with production modules

Alternatives considered

Moving all tests into the tests/ directory was considered but rejected because many tests need access to private items and would require widening visibility.

Acceptance criteria

  • Every test module in lib.rs and modules/mod.rs is behind #[cfg(test)]
  • cargo build --release for the contract succeeds without compiling test modules
  • cargo test still runs the full existing suite unchanged
  • PR reviewed and approved.

Additional context

Resources: contracts/predict-iq/src/lib.rs, contracts/predict-iq/src/modules/mod.rs, contracts/predict-iq/src/test.rs, issue #‍1716 (precedent)

Complexity: Trivial (100 points)

Source: Simple repository audit, item #‍1.


Drafted with Simple and reviewed by @‍hman38705 before publishing.

#1840 Validate OracleConfig when a market is created

Summary

create_market in contracts/predict-iq/src/modules/markets.rs accepts an OracleConfig without validating it, so markets can be created with nonsensical thresholds or empty oracle sets. Invalid configs only surface later during resolution.

Motivation

An unvalidated OracleConfig can make a market unresolvable or resolve on stale data, and the failure appears after bets are placed. Closed issue #‍1715 already flagged this gap, and it compounds the oracle staleness problems in #‍1707.

Proposed solution

Scope & Acceptance Criteria

  • Add validation of OracleConfig fields (thresholds, min_responses, oracle identifiers) in the create_market path
  • Return a typed error from contracts/predict-iq/src/errors.rs on invalid config
  • Add unit tests covering rejected configs in markets_test.rs
  • Out of scope: Changing the oracle staleness check itself — covered by issue #‍1707
  • Out of scope: Changing how the Pyth exponent is applied — covered by issue #‍1706

Implementation Guidelines

  • Follow the existing error construction patterns in contracts/predict-iq/src/errors.rs
  • Mirror the validation test style in contracts/predict-iq/src/modules/markets_test.rs

Alternatives considered

Not separately evaluated beyond the out-of-scope notes in the Scope & Acceptance Criteria section above — this issue targets one specific, verified gap grounded in the current repository state.

Acceptance criteria

  • create_market rejects an OracleConfig with empty or zero-valued required fields
  • A typed error is returned and covered by a unit test
  • Valid OracleConfigs continue to create markets as before
  • PR reviewed and approved.

Additional context

Resources: contracts/predict-iq/src/modules/markets.rs, contracts/predict-iq/src/modules/oracles.rs, contracts/predict-iq/src/errors.rs, contracts/predict-iq/src/modules/markets_test.rs, issue #‍1715 (precedent)

Complexity: Medium (150 points)

Source: Simple repository audit, item #‍2.


Drafted with Simple and reviewed by @‍hman38705 before publishing.

#1841 Constrain create_market outcome count and label/description lengths

Summary

create_market in contracts/predict-iq/src/modules/markets.rs allows a single outcome and imposes no length limits on the description or option labels, so degenerate or oversized markets can be created. This wastes storage and produces markets that cannot be meaningfully resolved.

Motivation

A one-outcome market is trivially resolved and oversized labels inflate storage costs for every participant. Closed issue #‍1713 documented this gap, and it is independent of the oracle validation work.

Proposed solution

Scope & Acceptance Criteria

  • Require at least two outcomes in create_market
  • Add maximum length checks for description and each option label
  • Return typed errors from contracts/predict-iq/src/errors.rs
  • Add tests for the new bounds in markets_test.rs
  • Out of scope: Validating OracleConfig — covered by the separate oracle-config validation issue in this batch
  • Out of scope: Changing the native_token allowlist — covered by issue #‍1714

Implementation Guidelines

  • Use the existing error variants in contracts/predict-iq/src/errors.rs
  • Follow the assertion style in contracts/predict-iq/src/modules/markets_test.rs

Alternatives considered

Not separately evaluated beyond the out-of-scope notes in the Scope & Acceptance Criteria section above — this issue targets one specific, verified gap grounded in the current repository state.

Acceptance criteria

  • create_market rejects fewer than two outcomes
  • create_market rejects descriptions and labels over the defined maximum length
  • Tests cover each rejection path
  • PR reviewed and approved.

Additional context

Resources: contracts/predict-iq/src/modules/markets.rs, contracts/predict-iq/src/errors.rs, contracts/predict-iq/src/modules/markets_test.rs, issue #‍1713 (precedent)

Complexity: Medium (150 points)

Source: Simple repository audit, item #‍3.


Drafted with Simple and reviewed by @‍hman38705 before publishing.

#1842 Validate user address and market id path parameters before cache and RPC use

Summary

services/api/src/handlers.rs uses user address and market id path parameters directly in cache keys and RPC calls without validating their format. Malformed values reach the cache layer and the Stellar RPC, producing confusing errors and cache pollution.

Motivation

Unvalidated path parameters let arbitrary strings become cache keys and RPC arguments, which can poison caches and trigger avoidable upstream calls. Closed issue #‍1737 identified this gap and it is a prerequisite for reliable error responses.

Proposed solution

Scope & Acceptance Criteria

  • Add format validation for user address and market id in the relevant handlers
  • Return a 400 with a typed error before touching cache or RPC
  • Add tests in services/api/tests/request_validation_middleware_tests.rs
  • Out of scope: Changing the cache key schema itself
  • Out of scope: Changing RPC client behaviour in services/api/src/blockchain.rs

Implementation Guidelines

  • Reuse the validation helpers in services/api/src/validation.rs
  • Follow the error-response conventions in services/api/src/handlers.rs

Alternatives considered

Not separately evaluated beyond the out-of-scope notes in the Scope & Acceptance Criteria section above — this issue targets one specific, verified gap grounded in the current repository state.

Acceptance criteria

  • Invalid user addresses and market ids return 400 without a cache or RPC call
  • Valid parameters behave as before
  • Tests cover both valid and invalid inputs
  • PR reviewed and approved.

Additional context

Resources: services/api/src/handlers.rs, services/api/src/validation.rs, services/api/tests/request_validation_middleware_tests.rs, issue #‍1737 (precedent)

Complexity: Medium (150 points)

Source: Simple repository audit, item #‍4.


Drafted with Simple and reviewed by @‍hman38705 before publishing.

Summary

The contract already contains partial implementations of the #1840/#1841 checks (validate_oracle_config, MIN_OUTCOMES_PER_MARKET, MAX_DESCRIPTION_BYTES, MAX_OPTION_BYTES, DescriptionTooLong, InvalidOptionLength, InvalidOracleConfig); verify each path returns the correct typed error and add the missing InsufficientOutcomes variant if the single-outcome path still returns InvalidOutcome. For #1839, gate each test module declaration individually rather than with a single catch-all, and verify with cargo build --release that test modules are excluded while cargo test still runs the full suite. For #1842, validation must short-circuit before any cache key construction or RPC call; keep the cache key schema and blockchain.rs untouched.

Changes

  • Add #[cfg(test)] to every test-only module declaration in contracts/predict-iq/src/lib.rs (test.rs, query_tests.rs, test_cancellation.rs, test_cancellation_referral.rs, test_classic_assets.rs, test_deposit_tier_reputation.rs, test_disputes_winner_count.rs, test_multi_outcome_voting.rs, test_multi_token.rs, test_oracle_overflow.rs, test_payout_mode_immutability.rs, test_pyth_integration.rs, test_referral.rs, test_resolution_state_machine.rs, and any other test/test modules). Apply the attribute individually to each declaration rather than a single catch-all, since they are interleaved with production modules. Do not modify test module contents. (contracts/predict-iq/src/lib.rs)
  • Ensure every test submodule declaration in contracts/predict-iq/src/modules/mod.rs (disputes_weight_test, event_archive_storage_test, governance_guardian_test, markets_conditional_test, migration_history_test, property_invariants_test, and any other *_test modules such as admin_test, bets_test, bets_fuzz_test, circuit_breaker_test, events_test, invariants_test, oracles_test) is individually gated with #[cfg(test)]. Add the attribute where missing; keep production module declarations ungated. (contracts/predict-iq/src/modules/mod.rs)
  • Add typed error variants for the new create_market bounds if not already present: InsufficientOutcomes (fewer than two outcomes) alongside the existing DescriptionTooLong, InvalidOptionLength and InvalidOracleConfig variants. Follow the existing #[contracterror] construction and numbering style. Ensure the variants are exported for use by markets.rs and tests. (contracts/predict-iq/src/errors.rs)
  • In create_market_with_dispute_window (called by create_market), enforce the market-shape bounds before any state writes: reject options.len() < MIN_OUTCOMES_PER_MARKET with the typed InsufficientOutcomes error (currently returns InvalidOutcome), reject description.len() > MAX_DESCRIPTION_BYTES with DescriptionTooLong, and reject empty or over-length option labels with InvalidOptionLength. Also ensure validate_oracle_config is invoked at the top of the create path and returns InvalidOracleConfig for empty/zero-valued required fields (empty or non-hex feed_id, zero max_staleness_seconds, min_responses of Some(0), max_confidence_bps > 10_000, oracle_address equal to the contract address). Keep valid configs and markets working as before; do not change the staleness check or Pyth exponent handling. (contracts/predict-iq/src/modules/markets.rs)
  • Add unit tests in markets_test.rs covering the new create_market validation paths: rejected OracleConfigs (empty feed_id, zero max_staleness_seconds, min_responses Some(0), over-limit max_confidence_bps) returning InvalidOracleConfig; fewer than two outcomes returning InsufficientOutcomes; over-length description returning DescriptionTooLong; empty and over-length option labels returning InvalidOptionLength; plus positive controls that a valid OracleConfig and a valid multi-outcome market still create successfully. Mirror the existing assertion style (client.try_create_market(...) compared against Err(Ok(ErrorCode::...))). (contracts/predict-iq/src/modules/markets_test.rs)
  • Add or confirm format validators in services/api/src/validation.rs for user addresses and market ids used as path parameters: validate_user_address (Stellar strkey / 0x-hex form) and validate_market_id (bounded ASCII alphanumeric plus '-'/'_'), each returning a ValidationError that renders as HTTP 400. These helpers are consumed by handlers.rs to reject malformed path parameters before any cache or RPC access. (services/api/src/validation.rs)
  • In services/api/src/handlers.rs, validate user address and market id path parameters at the start of the relevant handlers (e.g. user_positions, market_detail) using the validation.rs helpers, returning HTTP 400 with a typed ApiError before any cache lookup or Stellar RPC call. Valid parameters must behave exactly as before; do not change the cache key schema or blockchain.rs RPC client. (services/api/src/handlers.rs)
  • Add tests in services/api/tests/request_validation_middleware_tests.rs asserting that malformed user addresses and market ids yield HTTP 400 without invoking the downstream handler (proving no cache or RPC call occurs), and that valid addresses/market ids pass through and reach the handler as before. Reuse the existing HandlerSpy pattern and validate_user_address / validate_market_id helpers. (services/api/tests/request_validation_middleware_tests.rs)

Co-authored-by: Simple Agent <agent@simple.dev>
@drips-wave

drips-wave Bot commented Nov 23, 2026

Copy link
Copy Markdown

@ochayamary20 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant