Skip to content

feat: anti-frontrunning commit-reveal for scholarship applications (#262) - #1

Open
levibliz wants to merge 48 commits into
mainfrom
feat/anti-frontrunning-scholarship-262
Open

feat: anti-frontrunning commit-reveal for scholarship applications (#262)#1
levibliz wants to merge 48 commits into
mainfrom
feat/anti-frontrunning-scholarship-262

Conversation

@levibliz

Copy link
Copy Markdown
Owner

Summary

Implements anti-frontrunning protection for time-sensitive scholarship applications using a two-phase commit-reveal scheme.

Problem

Without protection, validators/miners can observe pending scholarship applications in the mempool and front-run them by submitting their own application with higher priority, stealing the scholarship slot.

Solution: Commit-Reveal Scheme

Phase 1 – Commit (commit_scholarship_application):

  • Student computes commit_hash = sha256(scholarship_id_xdr || amount_be || salt) off-chain
  • Submits only the hash — validators see nothing actionable

Phase 2 – Reveal (reveal_scholarship_application):

  • After COMMIT_MIN_DELAY (5 seconds), student reveals plaintext inputs
  • Contract recomputes the hash and verifies it matches the commitment
  • Commit expires after COMMIT_EXPIRY (3600 seconds) to prevent stale applications

Changes

lib.rs

  • ApplicationCommit struct: stores hash + timestamp
  • ApplicationReveal struct: stores verified plaintext
  • DataKey::AppCommit(Address), DataKey::AppReveal(Address)
  • ScholarErr variants: CommitNotFound=6, RevealTooEarly=7, RevealExpired=8, CommitHashMismatch=9
  • commit_scholarship_application and reveal_scholarship_application functions
  • Fixed pre-existing compilation errors: added missing functions (set_admin, transfer_scholarship_to_teacher, veto_course_globally, veto_course_access, add_course_to_registry, set_academic_oracle, report_student_gpa, get_student_gpa, get_student_gpa_bonus, get_scholarship, set_tuition_stipend_split, set_streak_bonus_amount, update_learning_streak, get_learning_streak, check_poa_compliance, get_student_poa_state, pro_rated_refund)
  • Updated StudentGPA struct with last_updated and oracle_verified fields
  • Added TuitionStipendSplit struct with actual university token transfer

test.rs

  • 5 new tests: happy path, reveal too early, reveal expired, hash mismatch, reveal without commit
  • Added MockOracle contract for academic progress tests
  • Fixed fund_scholarship call signatures

issue_batch.rs

  • Updated StudentGPA default construction to include new fields

Tests

Test Expected
test_commit_reveal_happy_path Commit + reveal succeeds after min delay
test_reveal_too_early_panics Panics if reveal before COMMIT_MIN_DELAY
test_reveal_expired_panics Panics if reveal after COMMIT_EXPIRY
test_reveal_wrong_hash_panics Panics on hash mismatch
test_reveal_without_commit_panics Panics with CommitNotFound

Closes Stream-Scholar#262

Tebrihk and others added 30 commits April 28, 2026 18:38
…ar#252 Stream-Scholar#265 Stream-Scholar#261)

- Implement automated telemetry for oracle polling error rates (Issue Stream-Scholar#268)
- Prevent precision loss in pro-rata distribution (Issue Stream-Scholar#252)
- Prevent re-initialization of core scholarship variables (Issue Stream-Scholar#265)
- Refactor dynamic arrays to bounded vectors to optimize Wasm footprint (Issue Stream-Scholar#261)

Security Hardening:
- Added telemetry system to monitor oracle call success/failure rates
- Implemented precision-safe distribution calculations to prevent rounding errors
- Added initialization protection to prevent contract re-initialization attacks
- Bounded vector validation to prevent gas exhaustion attacks

Reliability Improvements:
- Oracle error rate monitoring with automated alerts
- Precision-safe tuition stipend and royalty distributions
- Enhanced initialization validation and admin protection
- Optimized memory usage with bounded collections
…lar-solvency-invariant

Github Action on Scholar solvency invariant
feat: implement core scholarship contract structures and constants for Stream Scholar protocol
feat: implement foundational Soroban scholarship contract structs and constants
…ct-require-auth-enforcement

github action on require auth enforcement
…flow_underflow_safeguards

Add: integer overflow/underflow safeguards using Soroban native safe …
…uzz_testing

Add exhaustive fuzz testing for partial claim edge cases and rounding…
…wback-reconciliation

feat: add SAC clawback reconciliation and parity healing
…Scholar#46)

- Add CourseMetadata struct for IPFS links per language
- Modify CourseInfo to include default_language and available_languages
- Add storage keys for multi-language metadata management
- Implement course registration with multi-language support
- Add metadata update/retrieval/removal functions
- Include validation for language codes and IPFS links
- Add comprehensive test suite for multi-language functionality
- Support 40+ ISO 639-1 language codes
- Admin-only access controls for metadata operations
…ture

- Add detailed API documentation for new functions
- Include usage examples and code snippets
- Document supported languages and data structures
- Explain security features and storage architecture
- Provide testing instructions and future enhancement roadmap
Luchistack and others added 18 commits April 29, 2026 04:29
…cations (Stream-Scholar#262)

- Add ApplicationCommit and ApplicationReveal structs for two-phase application
- Add DataKey::AppCommit and DataKey::AppReveal storage keys
- Add ScholarErr variants: CommitNotFound, RevealTooEarly, RevealExpired, CommitHashMismatch
- Add COMMIT_MIN_DELAY (5s) and COMMIT_EXPIRY (3600s) constants
- Implement commit_scholarship_application: stores sha256 hash commitment
- Implement reveal_scholarship_application: verifies hash, enforces delay/expiry window
- Add 5 tests covering happy path, too-early reveal, expired commit, hash mismatch, missing commit
- Fix pre-existing compilation errors: add missing contract functions and update StudentGPA struct
- Add TuitionStipendSplit struct with actual university token transfer logic
- Add MockOracle contract for academic progress tests
- Implement comprehensive string validation module (string_validation.rs)
- Add validation for student IDs, achievements, metadata, symbols, and bytes
- Prevent XSS, injection attacks, and malformed inputs
- Add 12 new error codes (601-612) for validation failures
- Integrate validation into StudentProfileNFT and main scholarship contracts
- Add 30+ comprehensive test cases for all validation scenarios
- Create detailed documentation and migration guide
- Update README with security features section

Security improvements:
- Block malicious patterns (script tags, javascript:, eval(), etc.)
- Enforce length limits to prevent DoS attacks
- Validate email formats for student IDs
- Filter characters per field type requirements
- Sanitize all metadata inputs

This addresses the security hardening requirements for scholarship metadata
and prevents empty/malformed strings throughout the platform.
…ction spam

- Add rate limiting constants and data structures
- Implement sliding window rate limiting for claim_scholarship (3/hour)
- Implement stricter rate limiting for claim_scholarship_private (2/hour)
- Implement strictest rate limiting for claim_final_release (1/day)
- Add admin override function reset_student_rate_limits for emergencies
- Add comprehensive test suite covering all rate limiting scenarios
- Add RateLimitError enum for specific error handling
- Ensure per-student independent rate limiting with automatic window reset

This implementation prevents transaction spam while maintaining legitimate access
and provides emergency override capabilities for administrators.
…imiting-implementation

Implement rate limiting on student claim functions to mitigate transa…
…-validation-hardening

feat: Add robust string validation for scholarship metadata
…age-structs

refactor: group scalar storage variables into ProtocolConfig struct Stream-Scholar#249
…9-event-driven-assertions

fix: add event-driven assertions in unit tests to ensure strict state…
…anguage-metadata

Feature/multi language metadata
…-contract-call-bounds-to-limit-gas-consumption-per-scholarship-claim

feat: implement gas consumption limits for scholarship claims and add…
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.

Implement anti-frontrunning protection for time-sensitive scholarship applications