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.

v0 source pure

Package drand verifies drand "evmnet" beacons on gno.land and turns them into randomness.

Readme View source

drand evmnet verifier — unmodified copy of gnolang/gno#6268 p/drand/v0

This package is a verbatim copy of examples/gno.land/p/drand/v0 from the open pull request gnolang/gno#6268 ("drand randomness"), head commit 31c3e018dac4053f7cd538be515e5c8570e657a1, author albttx. Every .gno file is byte-identical to that commit; the only change is the module line in gnomod.toml, which places it in Sinopia's namespace (gno.land/p/g1jz6j9hj6rdf5ltl2kcrpa4jwtdh3w30z0yul06/sinopia/drand/v0) because the canonical path gno.land/p/drand/v0 is not deployed on any chain yet.

SHA-256 of the copied files (first 16 hex): drand.gno e678c1c8ecbed7d0, field.gno 6a0e9007a99eca98, hash.gno a652d727eab9d3df, drand_test.gno 25ad6f64ab5d6def, vectors_test.gno 9db945dbfc98dc55.

It is kept only until #6268 lands and gno.land/p/drand/v0 is deployed upstream; Sinopia's provider then switches to the canonical import (a new provider realm path + randomness.add). Do not edit the logic here: fixes go upstream, and the copy is refreshed byte-for-byte.

What it does: verifies drand evmnet beacons (BN254, scheme bls-bn254-unchained-on-g1, 3 s rounds) in pure Gno on the crypto/bn254, keccak256, modexp natives that gno v1.7.0 ships; Randomness = sha256(sig). Used by realms/r/randomness/drand.

License

Copyright (C) 2025 NewTendermint, LLC (the gno repository; this code was contributed to it by albttx).

This program is free software: you can redistribute it and/or modify it under the terms of the GNO Network General Public License as published by NewTendermint, LLC, either version 6 of the License, or (at your option) any later version published by NewTendermint, LLC. It is distributed in the hope that it will be useful, but is provided as-is and WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNO Network General Public License for more details.

The full license text, including its Additional Terms (Strong Attribution), is in LICENSE.md next to this file (copied unchanged from the gno repository at the same commit) and at https://gno.land/license. On chain the package carries this README (notice + link); LICENSE.md (38 KB) stays in the repository to avoid ~3.8 GNOT of storage deposit for a text that is published at the URL above.

Overview

Package drand verifies drand "evmnet" beacons on gno.land and turns them into randomness.

evmnet is the drand network that signs on the BN254 curve (scheme bls-bn254-unchained-on-g1, one beacon every 3 seconds). gno.land ships BN254 as native precompiles, so a beacon is checked fully on-chain: no trusted relayer, no oracle committee. Whoever submits a beacon can only submit the real one.

Verification: e(sig, G2) == e(H(m), pk), with m = keccak256(round) and H the RFC 9380 SVDW hash-to-curve, checked as one native pairing product.

Constants 2

const DST

1const DST = "BLS_SIG_BN254G1_XMD:KECCAK-256_SVDW_RO_NUL_"
source

DST is the hash-to-curve domain separation tag of the evmnet scheme.

Functions 8

func Derive

1func Derive(beacon [32]byte, salt string) [32]byte
source

Derive returns sha256(beacon || salt). Use a distinct salt per consumer and per draw so that two users of the same round get independent values.

func HashToG1

1func HashToG1(msg []byte) []byte
source

HashToG1 hashes msg onto G1 the way drand evmnet does (RFC 9380 hash_to_curve with expand_message_xmd/keccak256 and the SVDW map) and returns the 64-byte affine encoding x|y.

func Message

1func Message(round uint64) [32]byte
source

Message returns the digest drand signs for round: keccak256(uint64_be(round)).

func NewRand

1func NewRand(seed [32]byte) *rand.Rand
source

NewRand returns a deterministic PRNG seeded from 32 bytes of randomness, for drawing several values (IntN, Perm, Shuffle) from one beacon.

func Randomness

1func Randomness(sig []byte) [32]byte
source

Randomness returns the beacon randomness for sig, sha256(sig), the same value drand publishes as "randomness".

func RoundAt

1func RoundAt(t int64) uint64
source

RoundAt returns the latest round published at or before unix time t (0 before genesis).

func TimeOf

1func TimeOf(round uint64) int64
source

TimeOf returns the unix time at which round is published.

func Verify

1func Verify(round uint64, sig []byte) bool
source

Verify reports whether sig is the evmnet signature of round, checking e(sig, -G2) * e(H(m), pk) == 1. The pairing native rejects points off the curve and non-canonical coordinates.

Dependencies

Source Files 5