Refactor code structure for improved readability and maintainability#630
Open
Stanley-Owoh wants to merge 9 commits into
Open
Refactor code structure for improved readability and maintainability#630Stanley-Owoh wants to merge 9 commits into
Stanley-Owoh wants to merge 9 commits into
Conversation
|
@Stanley-Owoh is attempting to deploy a commit to the mAzI's projects Team on Vercel. A member of the Team first needs to authorize it. |
… snapshots - Fix badge_level computation in score_from_profile to derive dynamically from score via BadgeLevel::from_score, rather than reading stale stored value - Fix BadgeTier clone in set_badge_metadata to avoid use-after-move - Fix RoleMetrics::new() initial badge_level to match default score (Bronze) - Regenerate all Soroban test snapshots for the updated contract logic All 25 tests passing.
|
@Stanley-Owoh 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! 🚀 |
…ity and consistency - Removed unnecessary whitespace and adjusted formatting in `lib.rs` and `profile.rs`. - Consolidated function signatures for better clarity. - Enhanced error handling in arithmetic operations. - Streamlined badge level assignment logic in the `refresh_badges` method. - Updated function calls to maintain consistent formatting across the codebase.
…utation-system-robustness-auditing-403
…ithub.com/Stanley-Owoh/lance into reputation-system-robustness-auditing-403
soomtochukwu
requested changes
May 29, 2026
Contributor
soomtochukwu
left a comment
There was a problem hiding this comment.
- If you could fix the merge conflict(s) ASAP
- see that the CI checks pass
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.
SC-REP-049: Dynamic Rating Decay Parameters (Lambda Tuning)
Summary
Introduces configurable decay multipliers (
slash_decay_bps,blacklist_decay_bps) for the reputation contract, completing the lambda-tuning scope for dynamic reputation scoring. Replaces hardcoded decay constants with admin-settable storage-backed parameters, validated within a safe BPS range. Also includes badge metadata mapping (SC-REP-052) and automated badge minting (SC-REP-048) on the same contract surface.Files Changed
contracts/reputation/src/lib.rsset_slash_decay,set_blacklist_decay),submit_ratingauth hardening, blacklist flow with decay, badge reflection, profile metadata, upgrade guardcontracts/reputation/src/storage.rsProfileread/write with TTL management; safe default initializationcontracts/reputation/src/profile.rsBadgeLevel/BadgeTierenums,RoleMetrics,ReviewAggregate,Profilestruct withrefresh_badges()Key Features
[1_000, 10_000]; invalid values panic withInvalidInputi128checked math withSCORE_SCALE = 10_000BPS precisionget_badgeandget_public_metricsbadge_level = 0, blocks further reviewsupdate_score/slash/blacklist_profilerequire an explicitly registered caller contractDecayParameterUpdated,ScoreAdjusted,ReputationUpdated,BlacklistUpdated,AuthorizedContractUpdated,ContractUpgradedmetadata_hashviaupdate_profile_metadatawithrequire_authBadge Thresholds
Security Hardening
update_score,slash,blacklist_profilesubmit_ratingvalidates caller is job participant; non-participants rejectedReviewed(job_id, caller)key[1_000, 10_000]BPSupgraderequires admin auth with double-check patternaddress.require_auth()— only owner may writeinitializepanics ifAdminkey already exists — prevents re-init attack[0, 10_000]— prevents overflow manipulationTesting (21 tests, all passing)
Run:
cargo test -p reputationtest_empty_profile_reads_are_safetest_authorized_contract_updates_scoretest_slash_uses_fixed_point_decaytest_badge_upgrades_reflect_immediatelytest_blacklist_clears_badges_and_sets_flagtest_get_public_metrics_rejects_unknown_roletest_submit_rating_updates_pathstest_direct_score_adjustment_requires_authorized_contractupdate_scorerejectedtest_direct_reviews_from_unverified_keys_rejectedsubmit_ratingrejectedtest_profile_metadatatest_badge_starts_at_bronze/_to_silver/_to_goldtest_slash_downgrades_badgetest_set_and_get_badge_metadata(4 tests)test_default_slash_decay_matches_constanttest_admin_can_update_slash_decay/_blacklist_decaytest_non_admin_cannot_set_slash_decay/_invalid_values_rejectedtest_upgrade_requires_adminupgraderejectedReviewer Notes
apply_decay_bpsmultiplies score bydecay_bps / SCORE_SCALE. Slash (8,000 BPS = 0.8×) decreases scores; for increases useupdate_scorewith a positive delta.storage::read_profileextends TTL on every read — active profiles stay fresh; cold ones may need re-initialization.get_badge_metadataiterates over the Vec; bounded to 4 entries so effectively O(1).Reviewed(job_id, caller)prevents per-caller duplicates but allows both client and freelancer to review each other for the same job.Closes #403