Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

drand source realm

Package drand is a Sinopia randomness provider (core.RandomnessProvider) backed by the drand "evmnet" beacon, every r...

Overview

Package drand is a Sinopia randomness provider (core.RandomnessProvider) backed by the drand "evmnet" beacon, every round verified on chain.

Verification is gno.land/p/drand/v0 from gnolang/gno#6268, imported from its unmodified copy in Sinopia's namespace (realms/p/drand/v0/README.md; pure Gno on the crypto/bn254, keccak256, modexp natives of gno v1.7.0): evmnet signs on BN254 (scheme bls-bn254-unchained-on-g1, one round every 3 s), and Verify checks e(sig, G2) == e(H(round), pk). The randomness of a round is sha256(signature), the same value drand's API serves.

Trust: nobody. Submit is permissionless and only stores a round whose signature verifies against drand's group key, so a submitter can deliver a round or not, never choose or alter its value. Liveness needs at least one submitter (the Sinopia keeper, any relayer, the creator, a collector); if nobody submits, core falls back after ProviderWaitBlocks (CV-M1).

How core uses it (realms/r/core/randomness.gno):

  1. Target() is read in the transaction that binds a collection (the creator's reveal, RequestRandomness in the grace period, or the first Finalize after the deadline). It names the first evmnet round published more than MarginSeconds after the current block time, so its value is unknown to everyone, including the caller, when the bind is committed. Nobody passes a round: the caller cannot choose one.
  2. Anyone fetches that round from drand once it is published and calls Submit(round, signature) here.
  3. Anyone calls core.FulfillRandomness (or Finalize): core reads Randomness(round) and finalizes.

Clock assumptions (see README "drand provider"): time.Now() is the block header time, which tm2 sets to the median of the previous commit's vote times (BFT time), so a single proposer cannot move it. It lags wall clock by about one block (measured on Onyx: 4–7 s behind the newest block, blocks 3.3–5.4 s). MarginSeconds (30 s = 10 rounds) covers that lag, the 3 s propose timeout and ordinary validator clock skew. The one known case where block time is much older than wall clock is the first block after a chain halt (its time comes from the pre-halt commit); Target() then refuses (0) whenever a later round is already verified here, and core lets the bind happen later. An honest keeper submitting rounds as they are published makes that check effective.

Constants 1

const MarginSeconds, SigHexLen, maxList

1const (
2	// MarginSeconds: Target() is the first round published more than this
3	// many seconds after the block time (10 evmnet rounds).
4	MarginSeconds = int64(30)
5	// SigHexLen is an evmnet signature in hex (64 bytes, G1 point x|y).
6	SigHexLen = 2 * evmnet.SigSize
7	// maxList bounds Rounds() pages.
8	maxList = 100
9)
source

Functions 9

func Has

Action
1func Has(round int64) bool
source

Has reports whether round's randomness is stored here.

func Info

Action
1func Info() string
source

Info returns the provider's parameters and state as JSON.

func Latest

Action
1func Latest() int64
source

Latest is the highest round verified here (0 if none).

func Register

crossing Action
1func Register(cur realm) string
source

Register registers this provider with Sinopia core (once; anyone may send it). It stays inert until the admin approves it (timelocked randomness.add).

func Render

1func Render(path string) string
source

Render shows the provider on gnoweb.

func Rounds

Action
1func Rounds(offset, limit int64) string
source

Rounds lists stored rounds, newest first, as "round:randomness" lines.

func Submit

crossing Action
1func Submit(cur realm, round int64, signature string) string
source

Submit verifies round's drand evmnet signature (hex, the "signature" field of https://api.drand.sh/<ChainHash>/public/<round>) and stores its randomness. Permissionless; the caller is never trusted. A round already stored is a no-op (returns the stored value), so concurrent submitters never fail each other. Returns the randomness (64 hex characters).

func TargetAt

Action
1func TargetAt(unix int64) int64
source

TargetAt is the round a bind at block time unix would get, without the staleness check. For keepers and UIs.

func TimeOf

Action
1func TimeOf(round int64) int64
source

TimeOf is the unix time at which evmnet publishes round.

Dependencies

Source Files 2