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.

v1 source pure

Package qrc verifies Quantum Recovery Commits.

Overview

Package qrc verifies Quantum Recovery Commits.

The gno.land LAWS ("Quantum Proof Cryptography Roadmap", user accounts) ask for a protocol that registers each account with

Example
1two Merkle tree hash commits of at least 64 distinct Lamport signature
2public keys with one commit using only the sha256 hash function and the
3other commit using a different hash function family such as sha3
4(Quantum Recovery Commit) that can be used to securely register/sign-for
5at least 64 new arbitrary (e.g. quantum-proof) public key bytes of any
6length determined in the future (e.g. after "D-day") for each commit.

This package is the stateless half of such a protocol. It knows how to check that a message was signed by one of the one-time keys a commit stands for, and how the signed messages are laid out. It holds no state and no secret: keeping the commits and enforcing that every key signs at most once is the job of a realm.

Construction

Everything below exists twice, once per hash function H. The two copies never share a hash call, so a break of one function leaves the other commit intact.

A Lamport key has one pair of 32-byte secrets per bit of a 256-bit digest. Its public key is the 512 hashes H(secret), pair after pair:

Example
1PK = H(s[0][0]) || H(s[0][1]) || H(s[1][0]) || ... || H(s[255][1])

To sign a message, the signer hashes it with H. Bit number i of the digest, counting from the most significant bit of byte 0, selects one secret of pair i: s[i][0] if the bit is 0, s[i][1] if it is 1. The signature is the public key in which the hash of every selected secret is replaced by the secret itself:

Example
1signature = PK, with H(s[i][bit i]) replaced by s[i][bit i] for all i

It is as long as the public key. A verifier hashes the 256 selected values where they stand and gets the public key back, without ever having seen it: a signature made with another key, or for another digest, gives back other bytes.

The commit is the root of an RFC 6962 Merkle tree whose leaves are the public keys. It is the tree gno.land builds over its own blocks, the simple Merkle tree of Tendermint, for a number of leaves that is a power of two:

Example
1leaf  = H(0x00 || PK)
2inner = H(0x01 || left || right)

A proof is a signature followed by the sibling hashes on the way from the leaf to the root, bottom first. See Verify.

Cost

Checking a proof takes one hash of the message, whose cost grows with its length, then 257 hash calls for the signature, one of them over the 16385 bytes of a leaf, and one per tree level. A proof is 16384 bytes plus 32 per level: 16576 bytes for 64 keys, 16896 for 65536.

One-time keys

A Lamport key may sign a single message. Every further message signed with it reveals both secrets of more of its pairs and makes a forgery cheaper: a few such signatures make it easy. Verify cannot detect that. Whoever stores a commit must remember which leaves were used and refuse them forever, and a signer must treat a leaf as used as soon as a signature made with it leaves its hands, even if the transaction that carried it failed.

Constants 5

const DigestBits, PublicKeySize, SignatureSize, MinHeight, MaxHeight

 1const (
 2	// DigestBits is the number of digest bits a Lamport key signs, and so
 3	// the number of secret pairs in a key.
 4	DigestBits = HashSize * 8
 5
 6	// PublicKeySize is the size of a Lamport public key: two hashes per
 7	// digest bit.
 8	PublicKeySize = DigestBits * 2 * HashSize
 9
10	// SignatureSize is the size of a Lamport signature: the public key with
11	// one hash of each pair replaced by the secret it is the hash of.
12	SignatureSize = PublicKeySize
13
14	// MinHeight is the smallest tree a commit may use. It holds 64 one-time
15	// keys, the minimum the LAWS ask for.
16	MinHeight = 6
17
18	// MaxHeight is the largest tree a commit may use, 65536 one-time keys.
19	MaxHeight = 16
20)
source

const Domain

1const Domain = "QuantumRecoveryCommit/v1"
source

Domain opens every message signed with a commit key, so that such a signature can never be mistaken for anything else.

const HashSize

1const HashSize = 32
source

HashSize is the output size, in bytes, of both hash functions.

const ActionBind, ActionRotate, ActionAuthorize

1const (
2	// ActionBind registers new public key bytes for the account.
3	ActionBind Action = 1
4	// ActionRotate replaces the account's commit by a new one.
5	ActionRotate Action = 2
6	// ActionAuthorize approves a payload defined by another realm.
7	ActionAuthorize Action = 3
8)
source

const SHA256, Keccak256

1const (
2	// SHA256 is SHA-256 of FIPS 180-4, the SHA-2 family.
3	SHA256 Hash = 1
4	// Keccak256 is Keccak-256 with the original padding, as used by the
5	// EVM. It is the same sponge and permutation as SHA3-256 of FIPS 202
6	// and differs from it only in the padding byte.
7	Keccak256 Hash = 2
8)
source

Variables 1

var ErrUnknownHash, ErrHeight, ErrLeafIndex, ErrProofSize, ErrMismatch

1var (
2	ErrUnknownHash = errors.New("qrc: unknown hash function")
3	ErrHeight      = errors.New("qrc: tree height out of range")
4	ErrLeafIndex   = errors.New("qrc: leaf index out of range")
5	ErrProofSize   = errors.New("qrc: proof has the wrong size")
6	ErrMismatch    = errors.New("qrc: proof does not match the commit")
7)
source

Functions 6

func AuthorizeMessage

1func AuthorizeMessage(id ID, leaf uint32, app string, payload []byte) []byte
source

AuthorizeMessage returns the bytes to sign, with one-time key number leaf, in order to approve payload on behalf of the account. app is the package path of the realm the approval is meant for; no other realm can use it.

Example
1header || uint16 len(app) || app || uint32 len(payload) || payload

func BindMessage

1func BindMessage(id ID, leaf uint32, keyType string, key []byte) []byte
source

BindMessage returns the bytes to sign, with one-time key number leaf, in order to register key as the new public key of the account. keyType is a free label naming the scheme key belongs to.

Example
1header || uint16 len(keyType) || keyType || uint32 len(key) || key

The header common to all messages is

Example
1Domain || 0x00 || action || id.Bytes() || uint32 leaf

All integers are big-endian. Every variable-length field carries its length, so two different requests never produce the same bytes.

func Leaves

1func Leaves(height int) int
source

Leaves returns the number of one-time keys in a tree of the given height.

func ProofSize

1func ProofSize(height int) int
source

ProofSize returns the exact size, in bytes, of a proof for a tree of the given height: one signature and one sibling hash per tree level.

func RotateMessage

1func RotateMessage(id ID, leaf uint32, rootSHA256, rootKeccak256 [HashSize]byte, height int) []byte
source

RotateMessage returns the bytes to sign, with one-time key number leaf, in order to replace the commit id by a new one made of the two given roots and tree height.

Example
1header || rootSHA256 || rootKeccak256 || uint8 height

func Verify

1func Verify(h Hash, root [HashSize]byte, height int, leaf int, msg []byte, proof []byte) error
source

Verify checks a proof against a commit.

It returns nil when proof shows that msg was signed by the Lamport key stored at leaf of the Merkle tree of the given height whose root is root, everything hashed with h. The proof layout is described in the package documentation; its size must be exactly ProofSize(height).

Verify is a pure function of its arguments. It does not know whether the leaf has signed before: see the package documentation on one-time keys.

Types 3

type Action

ident
1type Action uint8
source

Action tells what a signed message asks for.

type Hash

ident
1type Hash uint8
source

Hash names the hash function a commit is built on. A commit uses its function for everything: public keys, message digests and tree nodes.

Methods on Hash

func String

method on Hash
1func (h Hash) String() string
source

String returns the name of the hash function.

func Sum

method on Hash
1func (h Hash) Sum(data []byte) [HashSize]byte
source

Sum returns the digest of data. It panics if h is not [Valid].

func Valid

method on Hash
1func (h Hash) Valid() bool
source

Valid reports whether h names a supported hash function.

type ID

struct
1type ID struct {
2	ChainID    string // chain the registry runs on
3	Registry   string // package path of the realm that stores the commit
4	Account    string // address of the account, as the chain writes it (lower-case bech32)
5	Generation uint32 // number of times the account replaced its commit
6}
source

ID identifies one commit: the n-th commit of an account, in one registry, on one chain. Messages carry it so that a signature made for one commit is worthless for any other, and signers derive their keys from it so that no one-time key is ever shared between two commits.

Methods on ID

func Bytes

method on ID
1func (id ID) Bytes() []byte
source

Bytes returns the canonical encoding of id: each string preceded by its length as a big-endian uint16, then the generation as a big-endian uint32.

Dependencies

Source Files 9