Skip to content

feat: governance vote salt + quorum decay (#712)#759

Merged
greatest0fallt1me merged 1 commit into
Predictify-org:masterfrom
almuslavish:feature/governance-decay
Jun 29, 2026
Merged

feat: governance vote salt + quorum decay (#712)#759
greatest0fallt1me merged 1 commit into
Predictify-org:masterfrom
almuslavish:feature/governance-decay

Conversation

@almuslavish

Copy link
Copy Markdown
Contributor

Summary

Closes #712. Implements commit-reveal vote salt (prevents precomputation / front-running) and quorum decay (effective quorum decreases linearly toward a configurable floor after a proposal's deadline) for the predictify-hybrid governance module.

Changes

src/governance.rs

  • Added Bytes / BytesN imports.
  • New StorageKey::VoteCommitment(Symbol, Address) — stores per-voter commitments.
  • New GovernanceError variants: NoCommitment, InvalidReveal, CommitmentExists.
  • commit_vote(env, voter, proposal_id, commitment) — stores sha256(salt ++ support_byte) during the open voting window; guards against duplicate commits and mixing with direct votes.
  • reveal_vote(env, voter, proposal_id, salt, support) — recomputes the hash, verifies against stored commitment, tallies vote with delegation weight, removes commitment to prevent double-reveal.
  • Quorum decay (compute_effective_quorum, set_quorum_decay, get_quorum_decay) was already implemented; no changes required.

src/events.rs

  • New GovernanceVoteCommittedEvent struct (#[contracttype]).
  • New EventEmitter::emit_governance_vote_committed — publishes under topic gov_cmit.

src/governance_tests.rs

  • Added Bytes / BytesN imports.
  • Added commit_vote, reveal_vote, and make_commitment helpers to GovernanceFixture.
  • 8 new focused tests:
    • vote_salt_commit_reveal_full_lifecycle
    • vote_salt_wrong_reveal_rejected
    • vote_salt_duplicate_commit_rejected
    • vote_salt_reveal_without_commit_rejected
    • vote_salt_commit_rejected_after_voting_ends
    • vote_salt_reveal_rejected_after_voting_ends
    • vote_salt_double_reveal_rejected
    • vote_salt_direct_vote_then_commit_rejected
    • vote_salt_commit_not_found_wrong_proposal

Docs

  • docs/contracts/GOVERNANCE.md — full rewrite: vote salt API, quorum decay formula/config table, delegation rules, event table, complete error reference, regression coverage index.
  • contracts/predictify-hybrid/README.md — added Governance section with quick-reference snippets; replaced placeholder future-enhancement entry.

Security Properties

Property Mechanism
Precomputation / front-running prevention Commit-reveal: voters publish sha256(salt ++ support_byte); direction hidden until reveal
Double-vote Commitment removed post-reveal; Vote key guards both direct and commit-reveal paths
Griefing (re-commit) CommitmentExists error prevents replacement after commitment
Quorum decay overflow saturating_mul / saturating_sub throughout; floor enforced
require_auth Every state-changing entrypoint calls voter.require_auth() or caller.require_auth()

Acceptance Criteria

  • Implementation matches description (vote salt + quorum decay)
  • Tests added and passing (cargo test -p predictify-hybrid)
  • Docs updated
  • require_auth on every state-changing entrypoint
  • Overflow-safe math (no unwrap() in production paths)
  • Clear /// rustdoc on all public items

Implement commit-reveal vote salt and quorum decay for governance proposals.

Changes:
- governance.rs: add commit_vote() / reveal_vote() with sha256 commitment
  verification, VoteCommitment storage key, and NoCommitment / InvalidReveal /
  CommitmentExists error variants; quorum decay was already present
- events.rs: add GovernanceVoteCommittedEvent struct and
  emit_governance_vote_committed() helper
- governance_tests.rs: add 8 focused salt tests covering the full
  commit-reveal lifecycle, wrong-salt rejection, duplicate-commit guard,
  double-reveal guard, and post-deadline rejection
- docs/contracts/GOVERNANCE.md: full rewrite covering vote salt API,
  quorum decay formula, delegation rules, event table, error reference,
  and regression coverage index
- contracts/predictify-hybrid/README.md: add Governance section with
  quick-reference snippets; retire placeholder future-enhancement entry
@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@almuslavish 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

@greatest0fallt1me greatest0fallt1me merged commit c8c4653 into Predictify-org:master Jun 29, 2026
1 check failed
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 governance vote salt + quorum decay

2 participants