Commit–Reveal
Randomness produced by a group instead of an operator. It's also useful for sealed-bid auctions and secret votes, because every revealed value is stored individually.
Lifecycle
| Phase | What happens |
|---|---|
| Commit | Each participant posts keccak256(abi.encode(roundId, participant, value, salt)) plus a bond |
| Reveal | Participants reveal value and salt. The contract checks them against the commitment |
| Finalize | Result = keccak(XOR of keccak(participant, value), roundId). No-shows forfeit their bond |
| Claim | Each revealer gets their bond back plus an equal share of forfeited bonds |
solidity
uint256 id = cr.createRound("Lottery seed", 60, 60, 0.01 ether, address(0)); // bond in HYPE
cr.commit{value: 0.01 ether}(id, commitment);
// after the commit window:
cr.reveal(id, value, salt);
// after the reveal window:
cr.finalize(id);
bytes32 result = cr.getRandomness(id);
cr.claim(id);The round creator picks the bond token: address(0) for HYPE, or the GENESIS token after launch. Bonds are deposits, not fees, so they're the same value in either token.
Making a commitment in TypeScript
ts
import { computeCommitment, randomBytes32 } from "@genesis/sdk";
const value = randomBytes32();
const salt = randomBytes32(); // keep this secret until you reveal
const commitment = computeCommitment(roundId, myAddress, value, salt);Keep your salt
If you lose value or salt you can't reveal, and you forfeit your bond.
Security note
The last person to reveal can choose to withhold, which gives them one bit of influence over the result. Set the bond higher than that bit is worth to an attacker.