Skip to content

Feat/deterministic pseudorandomness abstraction (#558)#693

Open
Chucks1093 wants to merge 3 commits intoJagadeeshftw:masterfrom
Chucks1093:feat/deterministic-pseudorandomness-abstraction
Open

Feat/deterministic pseudorandomness abstraction (#558)#693
Chucks1093 wants to merge 3 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

- Expanded traits.rs: added PauseInterface and FeeInterface with full
  doc comments referencing Grainlify internal spec
- BountyEscrowContract now formally implements all four traits
  (EscrowInterface, UpgradeInterface, PauseInterface, FeeInterface)
- soroban/contracts/escrow: added local EscrowInterface + UpgradeInterface
  trait definitions and implementations; added get_balance and
  get_escrow_info to satisfy standard surface
- grainlify-core: added local UpgradeInterface trait and impl for
  GrainlifyContract (feature-gated to match existing contract gate)
- contracts/view-facade: implemented ViewFacade contract with
  register/deregister/list/get_contract for cross-contract discovery
@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?

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