feat: anti-frontrunning commit-reveal for scholarship applications (#262) - #1
Open
levibliz wants to merge 48 commits into
Open
feat: anti-frontrunning commit-reveal for scholarship applications (#262)#1levibliz wants to merge 48 commits into
levibliz wants to merge 48 commits into
Conversation
…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
…r Stream Scholar protocol
issues 266,267,257,258
…curity-optimization-issues Fix security and optimization issues (Stream-Scholar#268 Stream-Scholar#252 Stream-Scholar#265 Stream-Scholar#261)
…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
… invariant checks
…or gas optimization (Stream-Scholar#249)
…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
… corresponding tests
…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
issues 235,238,242,260
…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…
issue 245,244,241,243
…anguage-metadata Feature/multi language metadata
…t-gas-consumption-per-scholarship-claim
…-contract-call-bounds-to-limit-gas-consumption-per-scholarship-claim feat: implement gas consumption limits for scholarship claims and add…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):commit_hash = sha256(scholarship_id_xdr || amount_be || salt)off-chainPhase 2 – Reveal (
reveal_scholarship_application):COMMIT_MIN_DELAY(5 seconds), student reveals plaintext inputsCOMMIT_EXPIRY(3600 seconds) to prevent stale applicationsChanges
lib.rsApplicationCommitstruct: stores hash + timestampApplicationRevealstruct: stores verified plaintextDataKey::AppCommit(Address),DataKey::AppReveal(Address)ScholarErrvariants:CommitNotFound=6,RevealTooEarly=7,RevealExpired=8,CommitHashMismatch=9commit_scholarship_applicationandreveal_scholarship_applicationfunctionsset_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)StudentGPAstruct withlast_updatedandoracle_verifiedfieldsTuitionStipendSplitstruct with actual university token transfertest.rsMockOraclecontract for academic progress testsfund_scholarshipcall signaturesissue_batch.rsStudentGPAdefault construction to include new fieldsTests
test_commit_reveal_happy_pathtest_reveal_too_early_panicstest_reveal_expired_panicstest_reveal_wrong_hash_panicstest_reveal_without_commit_panicsCloses Stream-Scholar#262