Skip to content

a wallthrough demo of Switchboard's verifiable randomness (VRF)

Notifications You must be signed in to change notification settings

ddm50/vrf-demo-walkthrough

 
 

Repository files navigation

Switchboard VRF Demo

This repo contains a step-by-step walkthrough to integrate Switchboard's VRF in a brand new anchor program.

You can checkout each step of the walkthrough with the command, wherethe tag is the step # in the table of contents below.

git checkout tags/0 -b main

Table of Contents

Background

VRF Demo Presentation

Switchboard's Verifiable Randomness Function (VRF) allows a user to request an oracle to produce a randomness output on-chain. Once the oracle has responded, the VRF proof must be verified before using it. The VRF proof takes 276 instructions (~40 transactions) to fully verify on-chain. Once the proof is verified, the Switchboard program will execute the callback defined by the VRF Account during account creation.

Client Program

Our client program will be very basic. It will initialize a state account to hold our randomness result. It will then request randomness from our Switchboard oracle. Once verified, the Switchboard program will call the consume_randomness instruction which will update our client's state.

So the full flow will look like this,

  • derive our client program derived address, vrfClientKey
  • create a Switchboard VRF Account with vrfClientKey as the authority. This will allow the client program to sign and request randomness.
  • invoke init_client for our vrfClientKey with our VRF Account
  • invoke request_randomness, which will assign an oracle to our VRF request
  • oracle watches the chain then responds to our VRF request with the proof calculated using its secret key
  • oracle executes the 276 instructions to verify the VRF proof
  • when VRF proof is verified, the Switchboard program will invoke our client program's consume_randomness instruction
  • Done!

About

a wallthrough demo of Switchboard's verifiable randomness (VRF)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 81.6%
  • Rust 18.4%