Verifiable randomness for Soroban smart contracts. A contract or an application requests a random value; an oracle answers with a BLS12-381 proof built on the drand quicknet beacon; the contract verifies the proof on-chain before it accepts the result.
No one can choose or change a result: not the oracle operator, not the contract admin, not the requester. If the operator fails to answer, the request is refunded.
Status. This is version 2 of the contract. It is live on Stellar Mainnet since 2026-12-06 (
CBJT2EP7R2TQKK7BUD7TGINBK75VJEMFPFJBQBS2KSGWS4RZMQKDQNNU) after validation on Testnet; see Deployments. It has an internal security review, not an independent audit.
Your dApp ──request()──▶ VRF contract ◀──fulfill(proof)── Oracle operator
│ │
│ drand beacon
▼ BLS-VRF proof
✓ proof verified on-chain (pairing checks)
✓ result stored and emitted
│
Your dApp ◀── get_beta() / derive_random_in_range() / on_vrf callback
request(context, requester) escrows the fee and binds the request to two
things that are fixed from that moment: the oracle key that is active now
(its key epoch) and a drand round that will be published 9–12 seconds
later. Nobody knows that round’s value yet.fulfill(). The contract checks the drand signature against the fixed drand
key and the VRF proof against the request’s oracle key. BLS signatures are
unique, so exactly one output can pass.beta) is stored and emitted. Read it with get_beta,
or derive an exactly uniform number in a range with
derive_random_in_range.on_vrf(id, beta, alpha) through
a separate deliver(id) transaction, which anyone can send or retry. A
failing callback cannot undo or block the result.fulfill() is accepted for 5 minutes. After that the request can only be
refunded (timeout_refund), and the fee goes back to the requester.| Choose or change a result | Nobody. The oracle key and the drand key are fixed before the drand round exists; the contract code is immutable (it has no upgrade function, and CI fails if the build could replace its own code). |
| Know the result when the request is made | Nobody. It depends on a drand round published later. |
| Withhold a result | The operator can (it sees the output a few seconds before publishing it), and so can the admin by revoking the key epoch. The request is then refunded. This gains nothing unless the application requests again for the same event, so an application must cancel a refunded draw, never re-request it. |
| Outside trust | drand’s threshold network, and a Stellar ledger clock that tracks real time. |
The admin is a multisig account, separate from the operator’s hot key. It can
rotate the operator’s keys (4 h timelock; applies only to later requests),
revoke a key epoch, and change the per-request fee (12 h timelock; never above
a maximum fixed at deployment; applies only to later requests). It cannot
change a result or the code. Details: docs/V2_SECURITY_MODEL.md.
| Network | Contract | Status |
|---|---|---|
| Mainnet | CBJT2EP7R2TQKK7BUD7TGINBK75VJEMFPFJBQBS2KSGWS4RZMQKDQNNU |
Live since 2026-12-06. WASM hash 776135101f817a851ed11112b5753ad230f3285c91b176e8955dc406cf9aa9e1 (commit af8aafc); deployment record: oracle-worker/deployed.v2.mainnet.json |
| Testnet | deployed per test run; addresses and transactions are in the security review | Validated |
The first version of the contract (V1, Mainnet
CAW6KECQMHRTX2GS3JVHWBMOB5JNNOHNOCE635RQS4SWJ72YF56EUPRX) is a different,
incompatible contract with a weaker trust model. Its code is on the
v1 branch and its documents
are in docs/v1/.
Requires Node.js ≥ 22.12. SDK 3.x is for this contract (2.x is for V1).
npm install stellar-vrf-sdk @stellar/stellar-sdk
import { VrfClient, VrfContractError, Networks } from "stellar-vrf-sdk";
import { Keypair } from "@stellar/stellar-sdk";
const client = new VrfClient({
contractId: "CBJT2EP7R2TQKK7BUD7TGINBK75VJEMFPFJBQBS2KSGWS4RZMQKDQNNU",
rpcUrl: "https://mainnet.sorobanrpc.com",
networkPassphrase: Networks.PUBLIC,
// Server-side only. Never put a secret key in a web page.
keypair: Keypair.fromSecret(process.env.VRF_REQUESTER_SECRET!),
});
// Freeze everything the outcome depends on BEFORE this line.
const requestId = await client.request(new TextEncoder().encode("raffle-42"));
try {
await client.waitForFulfillment(requestId, 330_000); // usually 10–30 s
const winner = await client.deriveRandomInRange(requestId, 1n, 1000n);
} catch {
await client.timeoutRefund(requestId); // no answer within 5 minutes: fee back
// cancel the draw; do NOT request again for the same event
}
A call the contract refuses throws a VrfContractError with the error’s name,
number and an explanation (for example TimeoutNotReached, 1060). Request ids
are 64-bit and not sequential: keep them as bigint.
Full reference: sdk/js/README.md.
// Request (the contract pays the fee from its own balance; it must
// pre-authorize the fee transfer, see consumer-example):
let id: u64 = env.invoke_contract(
&vrf,
&Symbol::new(&env, "request_with_callback"),
vec![&env, context, me.clone(), me, Symbol::new(&env, "on_vrf")],
);
// Callback, delivered by a separate deliver(id) transaction:
pub fn on_vrf(env: Env, id: u64, beta: BytesN<32>, _alpha: BytesN<32>) {
let vrf: Address = /* stored at construction */;
vrf.require_auth(); // only the VRF contract may call this
// accept only an id you requested, once; derive values locally from beta
}
consumer-example/ is a complete, tested contract, and
docs/CONSUMER_AUTHORIZATION.md lists what a
consumer must check. The Rust crate
stellar-vrf-sdk is a read/verify client for off-chain
Rust code (it does not submit transactions).
| Contract function | Output |
|---|---|
get_beta(id) |
the verified 32 bytes |
derive_random(id) |
a uniform u64 |
derive_random_in_range(id, max) |
a value in [0, max), exactly uniform (rejection sampling, no modulo bias) |
derive_range_for_domain(id, domain, max) |
the same with a domain separator, for several independent draws from one request |
Both SDKs reproduce these offline from beta, byte for byte (shared test
vectors). A domain must be a constant or a value stored before the
request: a domain chosen after the result is public can be tried until the
outcome suits whoever chooses it.
A request pays the contract’s fee in native XLM (fee(); 0.3 XLM on Mainnet at
launch, and never above the 10 XLM maximum fixed at deployment) plus the
network fee. The fee is paid to the operator on fulfillment and
returned in full on a refund. Read fee() when you request instead of
hard-coding it.
soroban-contract/ the VRF contract (Rust, Soroban)
oracle-worker/ the operator's worker (TypeScript) and the operator tools (v2_*.mjs)
consumer-example/ example consumer contract with callback
sdk/js/ sdk/rust/ the SDKs (stellar-vrf-sdk on npm and crates.io)
dashboard/ playground/ example-dapp/ docs-site/ the web pages
docs/ security model, security review, launch checklist, operations
cd soroban-contract && cargo test # 88 contract tests, real drand fixtures
cd oracle-worker && npm ci && npm test # worker tests
cd sdk/js && npm ci && npm test # SDK vectors and error table
cd sdk/rust && cargo test
CI runs all of these, clippy and rustfmt, a fuzz smoke run (10,000 runs per
target), a dependency audit, and a check that the release WASM cannot replace
its own code. fulfill() costs about 58M CPU instructions (Testnet
simulation), with or without a callback.
The operator’s worker serves one contract with one hot key that can only fulfill:
cd oracle-worker
cp .env.example .env # contract address, operator keys, RPC
npm ci && npm run build && npm start
Deployment, the admin multisig, monitoring and incident handling are in
docs/MAINNET_LAUNCH.md; running a primary and a
standby is in docs/HA_DEPLOYMENT.md.
| Document | |
|---|---|
docs/V2_SECURITY_MODEL.md |
trust model, roles, fee, errors, rules for consumers, key rotation |
docs/SECURITY_REVIEW_V2.md |
internal review: findings, fixes, Testnet evidence |
docs/MAINNET_LAUNCH.md |
launch checklist and incident quick reference |
docs/CONSUMER_AUTHORIZATION.md |
what a consumer contract must do |
docs/HA_DEPLOYMENT.md |
primary + standby workers |
docs/SDK_RELEASE.md |
SDK publishing |
sdk/js/README.md, sdk/rust/README.md |
SDK references |
MIT