Fairness ProtocolProtocol Spec
Draw Protocol Specification (v1.0.0)
Formal cryptographic specification of the Buzzeee commit-reveal verification standard. Designed for deterministic, bias-free, and independently auditable outcome generation.
Cryptographic Primitives & Inputs
For each winner rank $k \in [0, N-1]$, an unbiased pseudo-random integer $X_k$ is derived from an HMAC-SHA256 digest:
Canonical HMAC-SHA256 Digest Formulation
digest = HMAC_SHA256(serverSeed, `${clientSeed}:${drawIndex}:${rejectionAttempt}:${manifestHash}:${beaconValue}`)| Parameter | Type | Description |
|---|---|---|
| serverSeed | hex string (64 chars) | Secret 256-bit entropy generated and hashed prior to entry opening. |
| clientSeed | string | Operator or community-chosen string preventing single-party seed prediction. |
| drawIndex | uint32 | 0-indexed rank of winner being drawn (0 for 1st place, 1 for 2nd place, etc.). |
| rejectionAttempt | uint32 | Counter starting at 0, incremented if a digest falls outside the uniform modulo window. |
| manifestHash | hex string (64 chars) | SHA-256 hash of sorted entrant list formatted as `platform:userId:weight`. |
Elimination of Modulo Bias (Rejection Sampling)
Standard wheel apps use naive modulo arithmetic (X mod W) across the total pool weight W. When the 256-bit integer space (2^256) is not evenly divisible by W, the remainder causes lower numbers to have a statistically higher probability of winning.
Buzzeee guarantees uniform mathematical distribution by applying a strict rejection cutoff window:
Rejection Window Verification (TypeScript)
const DIGEST_SPACE = 1n << 256n;
const uniformLimit = DIGEST_SPACE - (DIGEST_SPACE % poolWeight);
// Parse 256-bit BigInt from hex digest:
const x = BigInt('0x' + digestHex);
if (x < uniformLimit) {
// Accepted: uniform mapping across poolWeight
const winningTicket = x % poolWeight;
return resolveWinner(winningTicket);
}
// Otherwise: reject and re-roll with rejectionAttempt + 1Reference Implementation
You can execute this complete, self-contained verification script in any Node.js or browser environment:
Independent Node.js Verifier
import crypto from 'crypto';
interface Entrant {
id: string;
weight: number;
}
export function verifyDraw(
serverSeed: string,
clientSeed: string,
manifest: Entrant[],
drawIndex = 0
): { winnerId: string; attempts: number } {
// 1. Calculate manifest hash
const canonical = manifest
.map(e => `${e.id}:${e.weight}`)
.sort()
.join('\n');
const manifestHash = crypto.createHash('sha256').update(canonical).digest('hex');
// 2. Compute total pool weight
const poolWeight = BigInt(manifest.reduce((sum, e) => sum + e.weight, 0));
const uniformLimit = (1n << 256n) - ((1n << 256n) % poolWeight);
// 3. Rejection sampling loop
let attempt = 0;
while (true) {
const payload = `${clientSeed}:${drawIndex}:${attempt}:${manifestHash}`;
const hex = crypto.createHmac('sha256', serverSeed).update(payload).digest('hex');
const x = BigInt('0x' + hex);
if (x < uniformLimit) {
const winningTicket = Number(x % poolWeight);
let current = 0;
for (const entrant of manifest) {
current += entrant.weight;
if (winningTicket < current) {
return { winnerId: entrant.id, attempts: attempt };
}
}
}
attempt++;
}
}