Skip to content

Feat/deterministic pseudorandomness abstraction (#558)#693

Merged
Jagadeeshftw merged 2 commits intoJagadeeshftw:masterfrom
Chucks1093:feat/deterministic-pseudorandomness-abstraction
Mar 5, 2026
Merged

Feat/deterministic pseudorandomness abstraction (#558)#693
Jagadeeshftw merged 2 commits intoJagadeeshftw:masterfrom
Chucks1093:feat/deterministic-pseudorandomness-abstraction

Conversation

@Chucks1093
Copy link
Contributor

Closes #558

Changes

  • contracts/grainlify-core/src/pseudo_randomness.rs

    • Added a deterministic pseudo-randomness helper module for verifiable on-chain selection.
    • Implemented seed derivation from:
      • domain tag
      • context bytes
      • external seed (BytesN<32>)
    • Implemented candidate selection by per-candidate hash scoring (instead of simple modulo), reducing index/order bias.
    • Documented security trade-offs and adversarial examples (seed grinding, timing bias, candidate stuffing).
  • contracts/grainlify-core/src/lib.rs

    • Exported shared helper via pub mod pseudo_randomness.
  • contracts/bounty_escrow/contracts/escrow/src/lib.rs

    • Integrated deterministic selection into claim-ticket flow with:
      • derive_claim_ticket_winner_index(...)
      • derive_claim_ticket_winner(...)
      • issue_claim_ticket_deterministic(...)
    • Added deterministic selection context construction using contract/bounty/amount/expiry/timestamp/ticket-counter material.
    • Added new error variant for invalid selection input.
  • contracts/bounty_escrow/contracts/escrow/src/events.rs

    • Added DeterministicSelectionDerived event for verifiable auditability of:
      • selected index
      • candidate count
      • selected beneficiary
      • seed hash
      • winner score
  • contracts/bounty_escrow/contracts/escrow/src/test_deterministic_randomness.rs

    • Added deterministic randomness tests:
      • same inputs => same winner
      • order-independent winner selection for the same candidate set
      • deterministic ticket issuance matches derived winner

Testing

  • contracts/grainlify-core

    • cargo test --lib
  • contracts/bounty_escrow/contracts/escrow

    • cargo fmt --check --all
    • cargo test test_deterministic_randomness -- --nocapture
    • cargo test --lib
    • cargo test --lib invariant_checker_ci

Notes

  • This is deterministic pseudo-randomness, not true randomness.
  • Verifiability is prioritized: any observer can recompute the selected winner from the published inputs.
  • Manipulation resistance depends on seed/context discipline; consumers should prefer commit-reveal style external seeds and bounded submission windows where applicable.

@vercel
Copy link

vercel bot commented Feb 26, 2026

@Chucks1093 is attempting to deploy a commit to the Jagadeesh B's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Jagadeeshftw
Copy link
Owner

@Chucks1093 please resolve the conflicts

@Chucks1093 Chucks1093 force-pushed the feat/deterministic-pseudorandomness-abstraction branch from d25f62b to ba255b3 Compare February 26, 2026 09:29
@Chucks1093
Copy link
Contributor Author

@Jagadeeshftw please merge this

@Jagadeeshftw
Copy link
Owner

@Chucks1093 Can you please resolve the conflicts?

@Chucks1093
Copy link
Contributor Author

Chucks1093 commented Mar 3, 2026

@Jagadeeshftw why did you close this? I wasn't given drips point for my PRs and decided to hault because something is wrong with the drips bot

@Jagadeeshftw Jagadeeshftw reopened this Mar 3, 2026
@Chucks1093
Copy link
Contributor Author

@Jagadeeshftw am working on this now

@Chucks1093 Chucks1093 force-pushed the feat/deterministic-pseudorandomness-abstraction branch from ba255b3 to d54f07f Compare March 5, 2026 12:54
@Chucks1093
Copy link
Contributor Author

@Jagadeeshftw pls merge this and reopen #696 thank you

@Jagadeeshftw Jagadeeshftw merged commit 6675204 into Jagadeeshftw:master Mar 5, 2026
1 of 4 checks passed
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.

Implement Deterministic Pseudo-Randomness Abstraction

2 participants