Drand
Garaga provides a maintained contract for verifying signatures from the drand distributed randomness beacon. This enables on-chain verification of publicly verifiable randomness.
What is drand?
drand is a distributed randomness beacon that provides:
Unpredictable randomness: Values cannot be known before generation
Unbiasable output: No single party can influence results
Public verifiability: Anyone can verify the randomness is legitimate
Regular intervals: New randomness every 3 seconds (quicknet)
Contract Information
Mainnet
0x59d24936725776758dc34d74b254d15f74b26683018470b6357d23dcab6b4bd
Sepolia
0x59d24936725776758dc34d74b254d15f74b26683018470b6357d23dcab6b4bd
Contract Interface
The drand verifier exposes a single function:
#[starknet::interface]
trait IDrandQuicknet<TContractState> {
fn verify_round_and_get_randomness(
self: @TContractState, full_proof_with_hints: Span<felt252>,
) -> Option<DrandResult>;
}
struct DrandResult {
round_number: u64,
randomness: felt252,
}Quicknet Configuration
The maintained contract is configured for drand's quicknet network:
Chain Hash
52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971
Public Key
G2 point on BLS12-381 (hardcoded in contract)
Period
3 seconds
Genesis
1692803367 (Aug 23, 2023)
Usage
Fetching drand Randomness
First, fetch randomness from drand's HTTP API:
Response:
Generating Calldata
Use the Garaga SDK to generate the full_proof_with_hints calldata from the drand response:
On-Chain Verification with Library Call
Use library_call_syscall to call the drand verifier contract:
Example: On-Chain Lottery
Security Considerations
Round timing: Ensure you're using the correct round for your application's timing requirements
Finality: Wait for sufficient confirmations before considering randomness final
Fallback: Consider implementing fallback mechanisms if drand becomes unavailable
Resources
Last updated
Was this helpful?