Skip to content

Add proptest fuzz suite for reputation & score arithmetic (closes #833) - #909

Open
p4uld4vid016-code wants to merge 2 commits into
Stellar-Ecosystem:mainfrom
p4uld4vid016-code:feat/fuzz-reputation-scoring
Open

Add proptest fuzz suite for reputation & score arithmetic (closes #833)#909
p4uld4vid016-code wants to merge 2 commits into
Stellar-Ecosystem:mainfrom
p4uld4vid016-code:feat/fuzz-reputation-scoring

Conversation

@p4uld4vid016-code

Copy link
Copy Markdown

Summary

Adds a proptest-based fuzz suite for the reputation/scoring arithmetic, closing #833.

The score and reputation updates used inline, hand-tuned clamps — exactly where
integer overflow and sign errors hide, and only verified against a few
hand-picked values. This extracts the arithmetic into pure helpers and
property-tests them across the full i32 domain.

Changes

contract/agents/src/lib.rs

  • Extracted score_after_success, score_after_failure, and score_after_flag
    from record_payment / flag_agent.
  • Converted the clamps to saturating arithmetic clamped to [0, MAX_SCORE], so
    the bounds hold for every i32 input — the previous math could overflow
    at i32 extremes and only clamped one side.
  • New mod proptests asserting:
    • score stays within [MIN_SCORE, MAX_SCORE] after any outcome
    • repeated failures / flags never underflow below zero
    • repeated successes never exceed MAX_SCORE
    • score + delta never overflows i32

contract/src/lib.rs

  • Extracted reputation_after_vote from update_reputation.
  • Saturating +1/-1 clamped to [MIN_REPUTATION, MAX_REPUTATION].
  • New mod proptests asserting:
    • reputation stays within bounds for all generated inputs
    • repeated positive votes never exceed MAX_REPUTATION
    • repeated negative votes never underflow MIN_REPUTATION
    • vote deltas never overflow i32

contract/Cargo.toml, contract/agents/Cargo.toml

  • Added proptest as a dev-dependency.
  • Kept overflow-checks = true on the test profile so any hidden overflow is
    caught by the fuzz tests instead of silently wrapping.

Verification

  • cargo +1.88 test passes in contract/ and contract/agents/ (39 and 23 tests incl. proptests).
  • New proptests run in CI via the existing cargo test steps.

Closes #833

p4uld4vid016-code and others added 2 commits August 29, 2026 19:09
…ollback

Voting posts to the backend and waits for the on-chain result, which
takes seconds. The card gave no feedback for that whole window, so the
vote button read as broken and invited double-clicks.

Apply the vote optimistically on click: the reputation number updates
instantly, a pending "casting vote" row appears, and the controls are
disabled until the real result arrives. The optimistic value is then
reconciled with the server-confirmed reputation, or rolled back with an
explanation when the vote fails. The artificial 1.5s settle delay is
removed since pending state now spans the actual request.

Closes Stellar-Ecosystem#837

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
…llar-Ecosystem#833)

Extract the pure scoring/reputation arithmetic out of the contracts so it
can be property-tested directly:
- agents: score_after_success/failure/flag, clamped to [0, MAX_SCORE], using
  saturating arithmetic so the bounds hold for every i32 input (the previous
  inline math could overflow at extremes and only clamped one side).
- registry: reputation_after_vote clamped to [MIN_REPUTATION, MAX_REPUTATION].

Add proptest suites in both crates asserting: score/reputation stays within
bounds for all generated inputs, repeated failures/flags/negative votes never
underflow, and repeated successes/positive votes never exceed the ceiling.
proptest is wired in as a dev-dependency and overflow-checks stay on for the
test profile. Fixes Stellar-Ecosystem#833.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@drips-wave

drips-wave Bot commented Aug 30, 2026

Copy link
Copy Markdown

@p4uld4vid016-code 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! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a3ee525c-324d-42e6-82da-6e093b082264


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Add a fuzz test for the reputation scoring arithmetic

1 participant