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.

doc.gno

3.17 Kb · 69 lines
 1// Package qrc verifies Quantum Recovery Commits.
 2//
 3// The gno.land LAWS ("Quantum Proof Cryptography Roadmap", user accounts) ask
 4// for a protocol that registers each account with
 5//
 6//	two Merkle tree hash commits of at least 64 distinct Lamport signature
 7//	public keys with one commit using only the sha256 hash function and the
 8//	other commit using a different hash function family such as sha3
 9//	(Quantum Recovery Commit) that can be used to securely register/sign-for
10//	at least 64 new arbitrary (e.g. quantum-proof) public key bytes of any
11//	length determined in the future (e.g. after "D-day") for each commit.
12//
13// This package is the stateless half of such a protocol. It knows how to
14// check that a message was signed by one of the one-time keys a commit
15// stands for, and how the signed messages are laid out. It holds no state
16// and no secret: keeping the commits and enforcing that every key signs at
17// most once is the job of a realm.
18//
19// # Construction
20//
21// Everything below exists twice, once per hash function H. The two copies
22// never share a hash call, so a break of one function leaves the other
23// commit intact.
24//
25// A Lamport key has one pair of 32-byte secrets per bit of a 256-bit digest.
26// Its public key is the 512 hashes H(secret), pair after pair:
27//
28//	PK = H(s[0][0]) || H(s[0][1]) || H(s[1][0]) || ... || H(s[255][1])
29//
30// To sign a message, the signer hashes it with H. Bit number i of the digest,
31// counting from the most significant bit of byte 0, selects one secret of
32// pair i: s[i][0] if the bit is 0, s[i][1] if it is 1. The signature is the
33// public key in which the hash of every selected secret is replaced by the
34// secret itself:
35//
36//	signature = PK, with H(s[i][bit i]) replaced by s[i][bit i] for all i
37//
38// It is as long as the public key. A verifier hashes the 256 selected values
39// where they stand and gets the public key back, without ever having seen
40// it: a signature made with another key, or for another digest, gives back
41// other bytes.
42//
43// The commit is the root of an RFC 6962 Merkle tree whose leaves are the
44// public keys. It is the tree gno.land builds over its own blocks, the
45// simple Merkle tree of Tendermint, for a number of leaves that is a power
46// of two:
47//
48//	leaf  = H(0x00 || PK)
49//	inner = H(0x01 || left || right)
50//
51// A proof is a signature followed by the sibling hashes on the way from the
52// leaf to the root, bottom first. See [Verify].
53//
54// # Cost
55//
56// Checking a proof takes one hash of the message, whose cost grows with its
57// length, then 257 hash calls for the signature, one of them over the 16385
58// bytes of a leaf, and one per tree level. A proof is 16384 bytes plus 32
59// per level: 16576 bytes for 64 keys, 16896 for 65536.
60//
61// # One-time keys
62//
63// A Lamport key may sign a single message. Every further message signed with
64// it reveals both secrets of more of its pairs and makes a forgery cheaper: a
65// few such signatures make it easy. [Verify] cannot detect that. Whoever
66// stores a commit must remember which leaves were used and refuse them
67// forever, and a signer must treat a leaf as used as soon as a signature made
68// with it leaves its hands, even if the transaction that carried it failed.
69package qrc