Drand
Garaga provides maintained contracts for the drand distributed randomness beacon. These enable:
On-chain signature verification of drand rounds for verifiable randomness
Time-lock encryption (tlock): encrypt data that can only be decrypted after a specific drand round is published
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)
What is tlock?
Time-lock encryption (tlock) leverages drand's BLS threshold signatures to create an identity-based encryption (IBE) scheme where the "identity" is a future drand round number. A message encrypted for round N can only be decrypted once drand publishes the signature for round N. No single party can decrypt early.
Use Cases
Sealed-bid auctions
Bids encrypted until auction close (a specific drand round)
Scheduled reveals
Information released at a predetermined time
Fair launches
Token distributions with time-locked claiming
Commit-reveal schemes
Players commit encrypted moves, revealed together after a round
Contracts
Drand Quicknet Verifier
Verifies drand BLS signatures and stores them on-chain.
Mainnet
0x1628f8e2d8ad8c26aea873b13703e4421f2c01a57c0c4974e599490ee30677d
Sepolia
0x1628f8e2d8ad8c26aea873b13703e4421f2c01a57c0c4974e599490ee30677d
Drand Decrypt Quicknet
Wraps the verifier to add on-chain tlock decryption. Deploy this contract yourself and point it at the verifier class hash.
The verifier contract is designed for library calls and does not need to be deployed. The decrypt contract wraps it and must be deployed since it stores signatures in its own storage.
Quicknet Configuration
Both contracts are 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)
Verifiable Randomness
Fetching drand Randomness
First, fetch randomness from drand's HTTP API:
Response:
Generating Verification 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:
Time-Lock Encryption (tlock)
How It Works
Message size: tlock encrypts a 16-byte (128-bit) message. For larger payloads, encrypt a symmetric key with tlock and use it to encrypt the larger data off-chain.
Encrypting a Message (Off-Chain)
Use the Garaga SDK to encrypt a message for a future drand round:
Decrypting On-Chain
The decrypt_cipher_text function on the decrypt contract handles two scenarios:
Round already verified: If the drand signature for the round is already stored, only the ciphertext calldata is needed.
Round not yet verified: The ciphertext calldata is followed by the drand verification hint, and both verification and decryption happen in a single transaction.
Scenario 1: Verify first, then decrypt
Scenario 2: Verify and decrypt in one transaction
Cairo: CipherText Struct
The tlock ciphertext is defined in garaga::apps::drand:
Cairo: Direct Decryption in Your Contract
If you want to call the decrypt_at_round function directly from the garaga library:
decrypt_at_round verifies ciphertext integrity (U = r·G₂) but does not verify that the provided signature is a valid drand BLS signature. You must verify the signature separately via verify_round or perform your own pairing check before calling this function.
Example: On-Chain Lottery
Example: Sealed-Bid Auction with tlock
A sketch of how tlock enables sealed-bid auctions. Bids are encrypted for a future reveal round. Once drand publishes that round, bids can be decrypted on-chain.
The ciphertext itself (a G2Point + 32 bytes) can be stored off-chain (e.g., IPFS) with only a commitment hash on-chain, or submitted directly in the decryption transaction.
Helper Functions
The garaga::apps::drand module provides utilities for working with drand rounds:
Security Considerations
Round timing: Ensure you're using the correct round for your application's timing requirements. Use
timestamp_to_roundto map wall-clock time to drand rounds.Message size: tlock encrypts exactly 16 bytes. Use it to encrypt a symmetric key for larger payloads.
Ciphertext integrity: The
decrypt_at_roundfunction verifiesU = r·G₂to ensure the ciphertext was formed correctly. Tampered ciphertexts will be rejected.Finality: Once a drand round is published, the signature is permanent. The ciphertext becomes decryptable by anyone with the round signature.
Fallback: Consider implementing fallback mechanisms if drand becomes unavailable.
Resources
tlock Paper — "tlock: Practical Timelock Encryption from Threshold BLS"
Last updated
Was this helpful?