fix(reputation): reject future-dated caller-supplied timestamps - #1232
Merged
Emeka000 merged 2 commits intoJul 26, 2026
Merged
Conversation
submit_rating, record_assignment, and flag_fraud stored a raw caller-supplied timestamp with no bounds validation. weighted_rating_score and decay_penalty key their weighting purely off this value, so a far-future timestamp gave permanent maximum recency weight and defeated inactivity decay entirely. Adds require_valid_timestamp, which rejects any timestamp greater than the current ledger time (Error::InvalidInput). Applied to all three write paths; update_from_event inherits the check since it delegates to record_assignment/flag_fraud.
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
submit_rating, record_assignment, and flag_fraud in the reputation contract now reject caller-supplied timestamps that lie in the future relative to ledger time, closing a way to permanently manipulate recency weighting and inactivity decay.
Context / before-after
Testing
cargo test -p reputation-contract - 54 passed, 0 failed. Fixed 6 existing tests that called these functions with a literal timestamp without advancing the mock ledger to match (they now set env.ledger().with_mut(...) first, matching realistic usage). Added 4 new tests: future-timestamp rejection for submit_rating, record_assignment, and flag_fraud, plus one confirming a timestamp equal to current ledger time is still accepted.
Closes #1128