Skip to content

Comments

feat: market reveal#44

Open
aguilar1x wants to merge 11 commits intoNetwalls:mainfrom
aguilar1x:feat/Market-reveal
Open

feat: market reveal#44
aguilar1x wants to merge 11 commits intoNetwalls:mainfrom
aguilar1x:feat/Market-reveal

Conversation

@aguilar1x
Copy link

Description

This PR implements the Market.reveal_prediction() function as specified in issue #4, completing the tier-3 prediction market reveal phase functionality.

Changes Made

Core Implementation

  • Added reveal_prediction() function in contracts/contracts/boxmeout/src/market.rs
    • Validates user authentication and market state
    • Reconstructs commit hash from outcome + amount + salt
    • Verifies hash matches stored commitment
    • Updates YES/NO prediction pools and total volume
    • Moves predictions from pending commits to predictions map
    • Emits PredictionRevealed event

Data Structures

  • Added Prediction struct for storing revealed predictions
  • Added storage constants for predictions map and error codes

Testing

  • Unit tests in contracts/contracts/boxmeout/tests/market_test.rs:

    • Happy path reveal with correct hash validation
    • Wrong salt/hash rejection
    • Reveal without prior commit rejection
    • YES and NO outcome path verification
    • Event payload correctness
  • Integration test in contracts/contracts/boxmeout/tests/integration_test.rs:

    • Complete commit-reveal flow with multiple users
    • Pool updates verification
    • Event emission confirmation

Bug Fixes

  • Fixed multiple type mismatches (BytesN vs Bytes)
  • Corrected function argument counts
  • Resolved event structure compatibility issues
  • Fixed literal overflow in test data

Acceptance Criteria Fulfilled

  • Auth required; user must have prior commit
  • Recompute hash(outcome + amount + salt) matches stored commit_hash
  • Update YES/NO pool, odds, total_volume
  • Move from pending commits to predictions map; clear pending entry
  • Emit PredictionRevealed(user, market_id, outcome, amount)
  • Unit + integration tests implemented and passing

Technical Details

Security Features

  • User authentication verification
  • Hash commitment validation using SHA256
  • Binary outcome validation (0 or 1)
  • Amount consistency checks
  • Market state validation (OPEN for revelations)

Storage Management

  • Persistent storage for predictions map
  • Atomic operations for pool updates
  • Proper cleanup of pending commitments
  • Event logging for transparency

Error Handling

  • Custom MarketError::InvalidRevelation for hash mismatches
  • Comprehensive validation at each step
  • Clear error messages for debugging

Files Modified

  • contracts/contracts/boxmeout/src/market.rs - Main implementation
  • contracts/contracts/boxmeout/tests/market_test.rs - Unit tests
  • contracts/contracts/boxmeout/tests/integration_test.rs - Integration tests

Testing

All tests pass with comprehensive coverage of:

  • Happy path scenarios
  • Error conditions
  • Edge cases
  • Multi-user interactions
  • Event verification

- Add reveal_prediction function with commit-reveal scheme validation
- Reconstruct hash from outcome + amount + salt and verify against commitment
- Update YES/NO pools and total volume on successful reveal
- Move predictions from pending commits to predictions map
- Emit PredictionRevealed event with full transaction data
- Add comprehensive error handling for invalid revelations
- Add test_reveal_prediction_happy_path: validates complete commit-reveal flow
- Add test_reveal_prediction_wrong_salt_rejected: hash validation error handling
- Add test_reveal_prediction_without_commit_rejected: missing commitment handling
- Add test_reveal_prediction_yes_and_no_outcomes: both outcome paths tested
- Add test_reveal_prediction_event_payload_correct: event emission verification
- Fix multiple BytesN vs Bytes type mismatches in hash computations
- Add test_commit_reveal_flow_with_pool_updates: multi-user commit-reveal scenario
- Test complete flow from market creation through prediction revelation
- Verify pool updates, commitment cleanup, and event emission
- Fix integration test initialization calls (treasury, oracle argument counts)
- Fix BytesN vs Bytes type mismatches in hash computations
- Fix event access issues with simplified verification approach
@GoSTEAN
Copy link
Contributor

GoSTEAN commented Jan 23, 2026

@aguilar1x fix conflict

@aguilar1x
Copy link
Author

aguilar1x commented Jan 23, 2026

@aguilar1x fix conflict

Ready, compliments are appreciated!

@aguilar1x
Copy link
Author

Hey @GoSTEAN

Updates with the pr?

@GoSTEAN
Copy link
Contributor

GoSTEAN commented Feb 2, 2026

@aguilar1x i am so sorry for the delay, i was cleaning up my repo and fixing up something
Your code looks great, just fix the CI and i will merge.

@aguilar1x
Copy link
Author

@GoSTEAN

Ready!

@GoSTEAN
Copy link
Contributor

GoSTEAN commented Feb 3, 2026

@aguilar1x
Screenshot 2026-02-03 at 17 18 16

@aguilar1x
Copy link
Author

@aguilar1x Screenshot 2026-02-03 at 17 18 16

Can you run cl again? To check if the format is working now.

@GoSTEAN
Copy link
Contributor

GoSTEAN commented Feb 3, 2026

@aguilar1x
Screenshot 2026-02-03 at 19 24 36
Clippy failed

@aguilar1x
Copy link
Author

@aguilar1x Screenshot 2026-02-03 at 19 24 36 Clippy failed

Approve the workflow again

@GoSTEAN
Copy link
Contributor

GoSTEAN commented Feb 3, 2026

@aguilar1x contract failed image

@aguilar1x
Copy link
Author

maybe already

@GoSTEAN

@GoSTEAN
Copy link
Contributor

GoSTEAN commented Feb 4, 2026

@aguilar1x contract is still failing

@aguilar1x
Copy link
Author

@aguilar1x contract is still failing

You have an error in your CI/CD because when compiling from contracts/contracts/boxmeout, Cargo writes the WASM file to the workspace target (contracts/target), not the crate target. That's why cp target/.../boxmeout.wasm fails in CI.

@GoSTEAN
Copy link
Contributor

GoSTEAN commented Feb 5, 2026

@aguilar1x my CI/CD works well the last time i checked, so how then doesn't it work for you?
Screenshot 2026-02-05 at 10 53 05

@aguilar1x
Copy link
Author

@aguilar1x my CI/CD works well the last time i checked, so how then doesn't it work for you? Screenshot 2026-02-05 at 10 53 05

That's strange, because the CI/CD couldn't find the path to the tests, which is why they weren't compiling.

On the other hand, it gave errors in tests I didn't run, but I improved my own.

Screenshot 2026-02-05 at 11 06 04 AM

@drips-wave drips-wave bot mentioned this pull request Feb 6, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Market.reveal_prediction() tier-3

2 participants