Applied Zcash

Pattern · Experimental

Memo stones

An author sends a memo in a shielded payment. A server calculates one hash from all the memos of a period and puts it in a public record. The author keeps a receipt.

With the receipt, anyone can find the memo in the record. The sender stays secret. The memo contains a hash of the text. Thus, the text stays secret until the author shows it.

Warning

This pattern is a proposal. It has no deployed service and no review. Use it on Testnet only.

Problem

A service must show in public that it received a text at a time. The sender and the text must stay secret. Examples are a research result of an agent, a sealed bid, and a report from an employee.

Only the recipient of a shielded payment can read its memo. Thus, outsiders cannot see that the service received the memo. In a public post, all persons can read the text.

One use is a retrospective grant for proof of agentic work. A lab records a claim of each result of its agents at the time of the work. Later, the lab shows the receipts to a funder as evidence. The time of each claim is in the transparent chain.

The funder sees that each text existed at the time of its record. The funder does not see who did the work: a receipt has no name of an author. To show the author, the lab can put a signature of a known key in the text.

When to use this pattern

Use it in these conditions:

A different design is better in these conditions:

Mechanism

Author
A person or an agent with a shielded wallet. The author writes the text.
App
A web page of the author. It calculates the text hash, and writes the memo and the payment link. It keeps the receipt in the browser.
Service
The operator of the reader and the writer.
Reader
A server with the incoming viewing key of the service. It finds payments and reads memos.
Writer
A server with one transparent key. It sends the record transactions.
Text hash
The hash of the text and a random text salt. It is the body of the memo.
Leaf
The hash of one memo. The memo contains a random salt.
Stone
The Merkle root of the leaves of one period. In a record on the chain, it cannot change.
Record
One stone in a transparent OP_RETURN, with a record number and a leaf count.
Receipt
The memo, the ID of the record transaction, and the path from the leaf to the stone.
The sequence from a salt to a stone 1: The author sends a shielded payment with the memo to the reader. 2: The reader gives the leaf to the writer. 3: The writer sends a record with the Merkle root, the stone, to the chain. 4: The writer publishes the leaf list. 5: The app of the author makes the receipt. author reader writer chain 1 payment, memo 2 leaf 3 record: stone 4 leaf list 5 makes the receipt
The reader and the writer are the service. The steps are in sequence from top to bottom.
  1. The app calculates the text hash from the text and a random text salt. It writes the memo from a topic, a random salt and the text hash. It shows a ZIP 321 payment link, and the author pays it from a shielded wallet.
  2. The reader finds the payment and examines the memo and the amount. It calculates the leaf and gives it to the writer. The writer does not receive the memo.
  3. At the end of each period, the writer calculates the root of the new leaves: the stone. It sends one record transaction with the stone.
  4. The service publishes the leaf list of the record. The list contains hashes only.
  5. The app finds its leaf in the list and completes the receipt. The author gives the receipt to a verifier at a later time.

The service sends no reply payment. The app uses public data only for steps 4 and 5. Thus, the author needs no account at the service.

As an option, the app puts the text in the memo as the body. Then the service can read the text. See Limits.

Record chain

Input 0 of each record transaction is output 1 of the record transaction before it. Nodes accept each spend of an output one time only. Thus, each record has one next record at most.

The service publishes the transaction ID of record 0. Thus, the writer cannot make a second history from record 0. A verifier examines the chain: see Receipt.

The service can cut off records only with a recovery. A recovery is a public record with a block time: see Keys.

Other designs

A Merkle root of hashes in an OP_RETURN is the design of OpenTimestamps. There, a client sends each hash to a calendar server through a web API. In this pattern, the author sends the hash in a shielded payment. With the shielded payment, the pattern has these properties:

Bound notes have the property of one history in a shielded pool. A service can put the stone in a bound note. Then a verifier needs the revealed fields of each record.

The records of this pattern are in the transparent pool. Thus, anyone can read each record and the time of its block with no key and no disclosure. A usual transparent wallet library is sufficient for the writer.

In Verified address, a server writes one salted hash in one bound note, for one user. In this pattern, the writer puts one root for the memos of many authors in each record.

What a verifier knows from a receipt

A receipt has no name of an author. Each holder of a receipt can show it. Thus, a receipt is good evidence that a text existed at a time. It is weak evidence of who wrote the text.

A receipt is evidence about one leaf only. It is no evidence that the record contains all the memos of its period. See Limits.

The salt and the text salt have 256 bits each. Thus, outsiders cannot find the memo of a leaf by guesses. The service cannot find the text of a text hash by guesses.

Keys

The reader has the incoming viewing key only. The writer has one transparent key. The funds for the fees and output 1 of the last record are under that key. The spending key of the service stays offline. See Watch-only keys.

A person who breaks into the reader gets the memos, and gets no funds. A person who breaks into the writer gets no memos. That person gets the fee funds and the control of the record chain. There are two risks:

To recover, the service makes a new writer key and sends a recovery record 0. This record contains the ID of the last correct record transaction of the old chain. The service publishes the ID of the recovery record. Verifiers then refuse the later records of the old chain. The receipts of the earlier records stay valid.

The recovery is a trust point. With a recovery, the service can also cut off correct records. Each recovery is on the chain and has a block time. Thus, a verifier sees a late recovery and the records after the last correct record.

Cost

Limits

Warning

With a text hash in the memo, the reader sees the topic and a hash only. With the text in the memo, the reader sees the text and the salt. Then the service can show each recorded text as its own. Put the text in the memo only if the service can read it safely.

Spec

The protocol of today is sufficient: the ZIP 302 memo format, ZIP 321 payment links and a transparent OP_RETURN. The formats in this section are the full spec. The test vectors are in demo/src/memo_stones.rs.

Memo

memo = "DO NOT MODIFY:{ms1/" topic "," salt "}" LF body

topic  1 to 32 characters: a to z, 0 to 9 and the hyphen
salt   64 hexadecimal characters in lowercase
LF     one line feed (0x0A)
body   the text hash as 64 hexadecimal characters in lowercase, or the text
text   UTF-8, 1 byte or more, without the character U+0000

The wallet shows the memo before it sends the payment. The first words are an instruction for the author. The header is 118 bytes at most. Thus, 394 bytes or more are free for the body.

The reader accepts this format only. It refuses a different prefix, a second comma in the braces, an empty body, and a body with U+0000. The reader removes the zero padding at the end of a memo. Thus, a text with U+0000 at its end has no correct leaf.

Text hash

text hash = BLAKE2b-256("MemoStones__Text", text salt ‖ text)

The text salt is 32 random bytes. The app makes it and keeps it with the text. With a text hash, the length of the text has no limit.

Leaf and root

leaf = BLAKE2b-256("MemoStones__Leaf", memo)
node = BLAKE2b-256("MemoStones__Node", min(a, b) ‖ max(a, b))

The input of the leaf hash is the memo bytes without the zero padding. The 16 characters in quotation marks are the BLAKE2b personalization. The two values are different, so a leaf is never valid as a node.

The writer compares two hashes as raw bytes, in lexicographic sequence. This rule is for the sequence of the leaves and for min and max.

  1. The writer drops each copy of a leaf. It puts the leaves in sequence, from the smallest value to the largest.
  2. The writer calculates one node from each pair of leaves, from the left. An odd last leaf goes up unchanged.
  3. The writer does step 2 again with the nodes, until one node stays. This node is the root: the stone.

The two inputs of each node are in sequence by value. Thus, a path is a list of hashes only. With one leaf, the root is the leaf.

Record

The record is the data of one OP_RETURN output:

  1. tag MST1 4 bytes
  2. version 1 byte
  3. number 4 bytes
  4. leaves 2 bytes
  5. root 32 bytes

Total: 43 bytes

The script of the output is 45 bytes: 0x6a (OP_RETURN), 0x2b (a push of 43 bytes) and the record.

The version is 1. The record number and the leaf count are big-endian. The first record has the number 0. Each later record has the number of the record before it, plus 1. The time of a record is the time of its block.

A record transaction has transparent inputs and outputs only:

input 0   output 1 of the record transaction before it
output 0  the OP_RETURN with the record, value 0
output 1  the change, to the record address of the service

A record transaction has exactly two outputs. The writer can add more inputs to pay the fees. The service publishes the transaction ID of record 0.

The service publishes a maximum delay, as a number of blocks. For each payment with a valid memo and amount, a record must contain the leaf. The block of that record is not more than the maximum delay after the block of the payment. Thus, an author can see a refusal at a known block.

Each record after record 0 has one leaf or more. For a period with no new leaves, the writer sends no record. Record 0 has a leaf count of 0. It has two forms:

first record 0     root = 32 zero bytes
recovery record 0  root = the ID of the last correct record transaction of the old chain

The ID in the root field has the byte order of a transaction input. This order is the opposite of the order that a block explorer shows. Input 0 of a record 0 has no rule.

Leaf list

The service publishes one file for each record. The file has the record number, the transaction ID, the root and all the leaves. Anyone can calculate the root from the leaves and compare it with the record on the chain.

Receipt

memo       the exact memo
txid       the ID of the record transaction
path       the hashes from the leaf to the root
text_salt  the text salt, for a memo with a text hash
text       the text, for a memo with a text hash

The author can show a receipt without the last two fields. Then the text stays secret.

A valid record transaction has these properties:

A verifier examines a receipt in these steps:

  1. The verifier examines the format of the memo.
  2. The verifier calculates the leaf from the memo.
  3. The verifier calculates the root from the leaf and the path.
  4. The verifier gets the record transaction and makes sure that it is valid. It compares the root with the root in output 0.
  5. The verifier gets the transaction with the output of input 0, and makes sure that it is valid. Input 0 must be its output 1. Its record number must be smaller by 1.
  6. The verifier does step 5 again for each record, back to record 0 of that chain.
  7. The verifier compares the ID of that record 0 with the ID that the service published. If they are equal, the chain is the current chain.
  8. If they are different, the verifier starts at the published record 0. It follows the root field of each recovery record to an older chain. It stops at the chain of the receipt.
  9. In an older chain, the verifier compares record numbers. The record of the receipt must have the number of the last correct record or a smaller number.
  10. The verifier reads the time of the block of the record transaction.
  11. If the receipt has a text, the verifier calculates the text hash. It compares the text hash with the body of the memo.

If one step fails, the receipt is invalid. In step 8, the verifier also examines each last correct record as in steps 4 to 6.

Demo: research claims

A lab uses agents for research. An agent sends the hash of a claim of each result in a memo. Each claim has the time of its record, and the results stay secret. The lab discloses one result later, with its receipt.

These are the values of the toy record:

Demo parameters
amount  0.001 ZEC
topic   research
record  number 7, with your leaf and 3 fixed leaves

The demo calculates the text hash, writes the memo and calculates the leaf. It makes the payment link, the record and the receipt. Then it examines the receipt as a verifier does. The two salts are random values from your browser.

The demo has no chain. The toy transaction ID is the SHA-256 hash of the record. The demo finds the record of the ID in the receipt. It does not examine the record chain.

To see an incorrect receipt, change one character of the memo or of the text in the receipt box.

Caution

The service address is a Testnet address. Its key is in the public source of this site. The demo has no reader and no writer. Thus, a payment to the link has no record.

Demo

Wait

Body of the memo

Memo and payment link

Record

Receipt

Receipt check

Change this page on GitHub