Hash-Signed Coin

The first quantum proof memecoin, signed with hashes inside a Token-2022 transfer hook

Overview

Hash-Signed Coin is a Token-2022 mint with a transfer hook. The hook program does four things. It lets a wallet seal its balance behind a hash-based key. It refuses to move a sealed balance unless a valid one-time signature over the exact transaction was verified earlier in that same transaction. It keeps exact totals of sealed, program-held and exposed supply. And it holds three bounty vaults that can only be opened by breaking an elliptic curve, changing the coin's transfer rules when one opens.

Everything on this site that is a number is read from Solana or from a price feed at the time you see it. A row with no value means the account behind it does not exist or has not been read yet.

Threat model

A Solana address is an ed25519 public key. Ownership of a token account is proven by a signature under that key. Shor's algorithm solves the discrete logarithm problem in polynomial time on a fault tolerant quantum computer, which means the private key can be computed from the address. No such machine is known to exist today. The design assumes one will, and asks what a coin can do about it from inside a program.

what the attacker hasunsealed walletsealed wallet
nothingsafesafe
the ed25519 private keybalance can be movedbalance cannot be moved
the ed25519 key and one pending signed transactionbalance can be movedcan only land that same transaction
the hash seed onlynothingnothing
the ed25519 key and the hash seedbalance can be movedbalance can be moved

The last row is the ordinary case of a fully compromised holder and no scheme changes it. The point of the table is the second and third rows.

Parameters

namevaluemeaning
N32bytes per chain value and per hash output
W16digit base, four bits per digit
LEN164digest digits
LEN23checksum digits
LEN67chains per key
SIG_BYTES2,144LEN times N
MAX_HASHES1,005LEN times 15
TAGhash-signed-coin/v1domain tag, ASCII
NODE_BYTES128node account size
COIN_BYTES96coin account size
CANARY_BYTES97canary account size
TX_BYTES4,096v1 transaction limit the layout is sized for

Keys and chains

A holder keeps one 32 byte seed. Every one-time key is derived from the seed and the key index, so the seed is the only thing to back up. The chain step binds the tag, the chain number and the step number into every hash, which keeps one chain's values from being reused in another chain or at another height.

fn secret(seed, index, j) = sha256(TAG || "sk" || seed || u64le(index) || u8(j))

fn step(j, i, x) = sha256(TAG || u8(j) || u8(i) || x)

fn chain(j, x, from, to):
    for i in from + 1 ..= to:
        x = step(j, i, x)
    return x

fn public_end(seed, index, j) = chain(j, secret(seed, index, j), 0, 15)

fn commitment(seed, index) =
    sha256(public_end(seed, index, 0) || ... || public_end(seed, index, 66))

Generating one key costs 1,005 hashes. A phone does this in a few milliseconds.

Signing

To sign a digest, cut it into 64 hex digits, compute the checksum, write the checksum as three more digits, and for each of the 67 digits reveal the chain value that many steps in.

fn digits(m):                       // m is 32 bytes
    d = []
    for byte in m:
        d.push(byte >> 4)
        d.push(byte & 15)
    c = 0
    for x in d: c = c + (15 - x)    // 0 ..= 960
    d.push((c >> 8) & 15)
    d.push((c >> 4) & 15)
    d.push(c & 15)
    return d                        // 67 digits

fn sign(seed, index, m):
    d = digits(m)
    return [ chain(j, secret(seed, index, j), 0, d[j]) for j in 0..67 ]

A worked split. The SHA-256 digest of the ASCII string hash-signed-coin is:

3b84c459ca52b3cecce0f836e13e69153d3b1e6bd088cf5ea7b1f11515fd78f0
quantityvalue
sum of the 64 digest digits500
checksum C = 960 - 500460
C in base 161 12 12
hashes the signer runs525
hashes the verifier runs480
total, always1,005

The signer and the verifier always share 1,005 hashes between them. A digest with small digits is cheap to sign and dear to verify, and the checksum digits push the other way, which keeps the verifier's work from ever reaching the maximum on real input.

Verification

The sign instruction carries the next commitment and the 67 chain values. The program rebuilds the digest itself from the node, the next commitment and the transaction, so the caller never supplies the message.

fn sign(ctx, next_commitment: [u8; 32], sig: [[u8; 32]; 67]):
    node = ctx.node                               // seeds: "node", mint, owner
    require(node.state == SEALED)
    require(coin.break_state != NATIVE_BREAK || node.state == SEALED)

    ix_hash = hash_instructions(ctx.instructions_sysvar)   // signature bytes zeroed
    m = sha256(TAG || mint || owner || u64le(node.key_index)
               || next_commitment || ix_hash)

    d = digits(m)
    ends = []
    for j in 0..67:
        ends.push(chain(j, sig[j], d[j], 15))
    require(sha256(concat(ends)) == node.commitment)       // else BadSignature

    node.commitment    = next_commitment
    node.key_index     = node.key_index + 1
    node.permit_hash   = ix_hash
    node.permit_amount = amount_of_next_transfer(ctx.instructions_sysvar)
    coin.signatures_verified = coin.signatures_verified + 1
    coin.last_signature_slot = clock.slot

If the transaction fails for any reason after this point, every write above is rolled back with it, including the key index. A failed transaction does not burn a key.

Transaction binding

hash_instructions walks the instructions sysvar from the first instruction to the last. For each one it hashes the program id, the number of accounts, every account key with its signer and writable flags, the length of the data, and the data. For the sign instruction itself the 2,144 signature bytes are replaced with zeros, since a signature cannot cover itself. The result is one 32 byte value that names the whole transaction.

The recent blockhash is not part of the instructions and is not covered. That is deliberate: a holder can sign, miss the blockhash window, and send the same instructions again with a fresh blockhash and the same signature, since the key index has not advanced.

What this prevents. Without binding, a party that sees a signed transaction before it lands, and that can also forge the ed25519 signature, could keep the hash signature and swap the destination. With binding, the only transaction that signature will ever authorise is the one the holder built.

Accounts

Three account types, all owned by the hook program, all program-derived. Discriminators are the first eight bytes of SHA-256 over the string account: plus the type name.

Coin account. Seeds ["coin", mint]. Discriminator bd 90 5c 57 27 50 3c 40.

offfieldtypemeaning
0discriminator[u8; 8]type tag
8mintPubkeythe coin
40sealed_supplyu64raw units held by sealed wallets
48program_supplyu64raw units held by off-curve owners
56signatures_verifiedu64count of accepted signatures
64transfers_seenu64count of hook executions
72last_signature_slotu64slot of the latest accepted signature
80break_slotu64slot of the latest state change, zero while intact
88sealed_walletsu32count of nodes
92break_stateu80 intact, 1 adjacent break, 2 native break
93canary_flagsu8bit 0 ed25519, bit 1 secp256k1, bit 2 secp256r1
94bumpu8PDA bump
95reservedu8zero

Node account. Seeds ["node", mint, owner]. Discriminator d0 35 01 03 31 7a b4 31.

offfieldtypemeaning
0discriminator[u8; 8]type tag
8ownerPubkeythe sealed wallet
40commitment[u8; 32]hash of the 67 public ends of the live key
72key_indexu64number of keys already spent
80permit_hash[u8; 32]instruction hash of the transaction in flight
112permit_amountu64raw units the permit allows
120stateu81 sealed
121bumpu8PDA bump
122reserved[u8; 6]zero

Canary account. Seeds ["canary", mint, [curve]]. Discriminator c0 d1 d6 c5 57 1c 52 73.

offfieldtypemeaning
0discriminator[u8; 8]type tag
8curveu80 ed25519, 1 secp256k1, 2 secp256r1
9claimedu80 or 1
10bumpu8PDA bump
11reserved[u8; 5]zero
16pubkey[u8; 33]the canary public key, compressed, ed25519 padded with one zero byte
49bountyu64raw units held by the vault
57claimerPubkeyzero until claimed
89claim_slotu64zero until claimed

The extra account list that Token-2022 reads before calling the hook lives at seeds ["extra-account-metas", mint]. It names the coin account, the instructions sysvar, and two node addresses seeded from the owner fields inside the source and destination token accounts, so wallets and pools resolve them with no special handling.

Instructions

instructiondiscriminatorsignereffect
initializeaf af 6d 1f 0d 98 9b eddeployer oncecreates the coin account, the extra account list and the three canary accounts
seal66 ca ab a3 1b 98 69 f2the walletcreates the node with the first commitment and moves the wallet's balance into the sealed total
sign05 dd 9b 2e ed 5b 1c ecthe walletverifies a signature, ratchets the key, writes the permit
claim_canary24 7b 74 92 6c 05 94 e7anyonepays a vault to the caller and advances the break state
execute69 25 65 c5 4b fb 66 1aToken-2022 onlyapplies the transfer rules below

execute is the transfer hook interface instruction. It checks that it is being called from inside a real transfer of this mint and rejects a direct call.

Execute rules

The hook classes each side of a transfer by its owner key. An owner that is not a point on the ed25519 curve is a program. An owner with a node account is sealed. Anything else is exposed.

sourceintactadjacent breaknative break
programpassespassespasses
sealedneeds a permitneeds a permitneeds a permit
exposedpassespassesrejected
destinationintactadjacent breaknative break
programpassespassespasses
sealedpassespassespasses
exposedpassesrejectedrejected

A permit matches when the node's permit hash equals the instruction hash of the current transaction and the permit amount equals the transfer amount. The hook zeroes both fields as it accepts. After the checks, the hook subtracts the amount from the source's class total and adds it to the destination's class total, then increments transfers_seen.

Key ratchet and recovery

The key index only moves forward and only inside a transaction that succeeds. A holder's software derives key i from the seed, signs, and learns from the node account that the index is now i + 1. There is no state to keep besides the seed.

Two things are final. A seed that is lost cannot be replaced, since replacing the commitment needs a signature under the current key. And a wallet cannot be unsealed. Both follow from the same rule: nothing but the hash key may speak for a sealed balance.

Exposure accounting

The mint's whole supply starts in program-held accounts, so the totals are exact from the first transfer. Sealed supply and program-held supply are stored. Exposed supply is the remainder, and the sealed share divides sealed supply by everything not held by programs.

E=S−Ssealed−Sprogram,q=SsealedS−SprogramE=S-S_{\mathrm{sealed}}-S_{\mathrm{program}},\qquad q=\frac{S_{\mathrm{sealed}}}{S-S_{\mathrm{program}}}

After a native break, E is the amount that has left the supply for good.

Canaries

A canary key is found by hashing until the output is a valid point. For ed25519 the candidate is sha256("hash-signed-coin canary ed25519" || mint || u32le(n)) read as a compressed point, for the smallest n that decompresses, multiplied by the cofactor 8. For the two Weierstrass curves the candidate is the same construction with the curve's name, reduced into the field and used as an x coordinate, for the smallest n that lies on the curve, taking the even y. Nobody chooses these points and nobody learns a private key by computing them.

curveclaim messagehow the program checks it
ed25519sha256("claim" || mint || 0 || claimer)a verified Ed25519 program instruction in the same transaction
secp256k1sha256("claim" || mint || 1 || claimer)the secp256k1 recover syscall
secp256r1sha256("claim" || mint || 2 || claimer)a verified Secp256r1 program instruction in the same transaction

The message names the claimer, so copying a claim from a pending transaction pays the original caller. A claimer who wants to move the bounty afterwards should seal the receiving wallet before claiming the ed25519 vault, because that claim freezes every exposed balance, the claimer's included.

Break states

State only moves forward: intact, then adjacent break, then native break, or straight from intact to native break. The move happens inside claim_canary and takes effect for the next instruction in the same transaction. No timer, epoch or admin is involved.

statewhat changedwhy
adjacent breakexposed wallets can no longer receivea neighbouring curve of the same family has fallen, so new balances must start out sealed
native breakexposed balances frozen and sealing closeda seal request signed with ed25519 can no longer be told from a forgery

Compatibility

whowhat they need to do
an unsealed holdernothing, the coin behaves like any transfer hook token
a sealed holder buyingnothing, receiving needs no signature
a sealed holder selling or sendingbuild a v1 transaction with sign first, using the open signer and their seed
a poolsupport Token-2022 transfer hook mints
an explorernothing, all accounts are plain program-derived accounts

A normal wallet app signs with ed25519 only and cannot send from a sealed wallet. That is the property working as intended.

Errors

codenameraised when
6000NotSealedsign is called for a wallet with no node
6001BadSignaturethe rebuilt commitment does not match
6002PermitMissinga sealed source has no permit for this transaction
6003PermitAmountthe transfer amount differs from the permit
6004ExposedReceivean exposed destination after an adjacent break
6005ExposedFrozenan exposed source after a native break
6006SealingClosedseal after a native break
6007AlreadySealedseal for a wallet that has a node
6008CanaryClaimedthe vault was already paid
6009BadCanaryProofthe claim signature does not verify
6010NotTransferringexecute called outside a transfer

What it does not cover

Solana's validators sign blocks and votes with elliptic curve keys. If those fall, the chain needs its own migration, and a token program cannot stand in for it. Transaction fees are paid by an ordinary key. The SOL or stablecoin received in a sale lands in an ordinary account. A wallet that never sealed has no protection at all, and after a native break its balance is frozen for good. A sealed wallet whose seed is lost is frozen for good as well. And the scheme assumes SHA-256 stays one-way: the quantum cost of inverting it is on the order of 2128 operations, which is the security level the whole design rests on.

Reading this site

what you seewhere it comes fromhow often
value and priceBirdeye price multiplied by on chain supplyevery second
supplySolana getTokenSupplyevery 30 seconds
chartBirdeye candles plus the live priceon load and every 15 minutes
token program, extension, hook programthe mint accounton load and every 30 seconds
coin account rowsthe coin account decoded byte by byteon load and every 30 seconds
canary rowsthe three canary accountson load and every 30 seconds
the lit latticeSHA-256 of the live value computed in your browserwhenever the value changes