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.

puzzlerounds source pure

Package puzzlerounds is the reusable, stateless puzzle-round library behind Riddle Tavern (gno.land/r/g1j7l6ekxy82r9t...

Overview

Package puzzlerounds is the reusable, stateless puzzle-round library behind Riddle Tavern (gno.land/r/g1j7l6ekxy82r9tav7d8jv3gp0h3xaunw2m2k3lx/riddletavern).

It holds the commitment scheme, the round record, streak math and leaderboard ordering, so any other realm or package can import it and run the same twice-daily puzzle game without copying the logic.

Answer commitment scheme (public, part of the game rules):

  • An answer is an integer. It is encoded as its decimal string (strconv.Itoa) and committed with sha256.
  • Only the hash is ever stored on-chain; the answer itself is never stored. Anyone can recompute HashAnswer to verify a round.
  • Note the honest limitation, shared with the BSC original this ports (Puzzle Arena, which used keccak256 the same way): small-integer answers are brute-forceable from the hash in principle. The hash is a commitment that the round cannot be changed after creation, not a vault. The game is the puzzle, the live window and one entry per player — not the secrecy of the answer.

Functions 5

func DayOf

1func DayOf(unix int64) int64
source

DayOf returns the UTC day number for a unix timestamp.

func NextStreak

1func NextStreak(lastDay int64, streak int, today int64) int
source

NextStreak computes the new streak after a solve on day today, given the day of the previous solve (lastDay, 0 if never) and the current streak. Ported from Puzzle Arena (BSC):

  • a second solve on the same day leaves the streak unchanged (two rounds run per day, so a same-day solve must not reset it),
  • a solve the day after the last one extends the streak by one,
  • anything else restarts the streak at 1.

func SortLeaders

1func SortLeaders(leaders []Leader)
source

SortLeaders sorts in place: most solves first, then highest streak, then lowest address (deterministic tie-break).

func VerifyAnswer

1func VerifyAnswer(hash AnswerHash, answer int) bool
source

VerifyAnswer reports whether answer matches the stored commitment.

func HashAnswer

1func HashAnswer(answer int) AnswerHash
source

HashAnswer computes the commitment for an answer.

The answer is encoded as its decimal string and hashed with sha256. The encoding is part of the public commitment scheme: anyone can recompute it to verify a round, and the answer itself is never stored.

Types 3

type AnswerHash

array
1type AnswerHash [32]byte
source

AnswerHash is a sha256 commitment to a puzzle answer.

type Leader

struct
1type Leader struct {
2	Solver address
3	Solves int
4	Streak int
5}
source

Leader is one row of the leaderboard.

type Round

struct
1type Round struct {
2	Question   string     // puzzle text, shown to players
3	AnswerHash AnswerHash // sha256(decimal answer); the answer is never stored
4	Start      int64      // unix seconds, inclusive
5	End        int64      // unix seconds, inclusive
6	Solves     int        // correct solves so far
7}
source

Round is the public record of one puzzle round. It carries no behaviour of its own; the realm that owns the round holds the state.

Methods on Round

func IsOpen

method on Round
1func (r Round) IsOpen(now int64) bool
source

IsOpen reports whether unix time now falls inside the round window.

Dependencies

Imports 2

/p/g1j7l6ekxy82r9tav7d8jv3gp0h3xaunw2m2k3lx/puzzlerounds

Imported by indexer

Source Files 3