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:
- other parties must see, at a later time, that the service received a text at a time;
- the text must stay secret until its author shows it;
- many authors send texts, and one record for each period is sufficient.
A different design is better in these conditions:
- Only the author and the service use the fact. Then the memo is sufficient, with no record.
- The text can be public. Then publish the text.
- One author needs a timestamp and no service. Then the author can write a hash in a bound note.
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 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.
- 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.
- 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.
- The service publishes the leaf list of the record. The list contains hashes only.
- 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:
- The service needs no web API and no accounts. Its payment address is the full interface.
- The service does not see a network address or an account of the author.
- The author pays the service for each memo. Thus, a sender of many false memos has a cost.
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
- The stone of the record contains this exact memo, with this topic.
- The service wrote the record, and the record has one place in the record chain.
- The memo existed at the time of the block.
- With the text and the text salt: the memo contains the hash of this exact text.
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:
- That person can send records with leaves of any value. Verifiers then accept them as records of the service.
- That person can spend output 1 of the last record in a different transaction. Then the record chain has no next record.
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
- Each memo One usual shielded payment with two actions. With the ZIP 2009 fee rule, the fee for two actions is 2,000 zatoshis.
- Each record One transparent transaction for all the memos of a period. Its two outputs are 88 bytes. In ZIP 317, that is three logical actions. With the ZIP 2009 fee rule, the fee is 3,000 zatoshis.
- Wallets A record transaction has no shielded actions. Thus, other wallets do no trial decryption for a record. See Polite actions.
- Receipt The memo and the path. A path in a record of n leaves has ⌈log₂ n⌉ hashes or fewer, of 32 bytes each. For 1,000 leaves, a path has 10 hashes or fewer.
-
Relay The
OP_RETURNscript of a record is 45 bytes. Nodes relay anOP_RETURNscript of 83 bytes or fewer. - Wallet support ZIP 321 with memos. The wallet must send the memo bytes unchanged.
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.
- Refusal. The service can ignore a payment and still send a valid record. After the maximum delay, the author can find a refusal if all relevant leaf lists are available and verified. With a missing list, inclusion stays unknown. To show the payment to other persons, the author needs a payment disclosure (ZIP 311, draft).
- Selection. The reader sees the full memo and the amount of each payment. With a text hash in the memo, the reader cannot read the text. Thus, the reader can select payments to ignore by the topic, the amount and the time. An author can tell the service the leaf of a memo. Thus, the service can keep that leaf and ignore the others. For sealed bids, each author must use the Receipt steps to verify a receipt. The authors must do this before they show their bids.
-
Enclave. As an option, the service can run the reader and the writer in an enclave, a trusted
execution environment (TEE). Then the enclave code puts each leaf in a record. These conditions are necessary:
- The enclave sends an attestation. The verifier examines the signature of the attestation. The verifier calculates the code hash from a reproducible build of the published source. The code hash must be the same as the hash in the attestation.
- The enclave examines full blocks. It gets the chain tip from sources that are independent of the operator. The operator can hold back block data. Then the enclave sends no records, and the authors see the delay.
- The writer key stays in the enclave. The writer public key must be in the verified attestation. For this option, the verifier checks this key against record 0 and each recovery record 0.
- Refunds. The sender of a payment is secret. Thus, the service cannot send back a payment with an invalid memo. The app must examine the memo and the amount before it shows the link.
- Timing. A record a short time after a payment is a possible link between the two. With a longer period and more leaves, the link is weaker.
-
Memo download. Compact blocks contain no memos. A reader gets each memo in a full transaction.
If it gets only payment transactions from a light wallet server, that server sees each payment transaction.
If it gets all transactions only from blocks with payments, that server sees those blocks.
A reader can use
GetMempoolStreamto receive all full transactions in the server's mempool. Thus, the reader receives those memos without payment-specific requests. For payments absent from the stream, the reader can useGetTransaction. If the author wallet and the reader use the same server, that server can link the IP address of the author to a payment to the service. Use a reader with its own node. - Leaf list. The leaf list is off the chain. If the service holds back a list, the authors cannot complete their receipts. The authors can see the delay.
- Empty leaves. The writer can put any hash in a record. Thus, the leaf count is the maximum number of real memos.
- Copies. The reader drops a leaf that is equal to a leaf of the open period or of a record. Thus, the record has no second leaf for a second payment with the same memo.
- Reorganization. The reader must wait for confirmations before it accepts a payment.
- Disclosure. A shown receipt stays public. It contains the topic of one leaf, and the text if the author shows it.
- Truth. A receipt is evidence that the service recorded a text at a time. It is no evidence that the text is true.
- Public data. The number of leaves of each period and the time of each record are public. Thus, outsiders see how much the service is used.
- Transparent funds. The fee funds of the writer are public, and so is their source. Use funds with no link to other addresses of the service.
- Writer key. A person with the writer key can send false records or stop the record chain. See Keys.
- Chain data. Each record stays on the chain. With a longer period, the chain has fewer records.
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.
- The writer drops each copy of a leaf. It puts the leaves in sequence, from the smallest value to the largest.
- The writer calculates one node from each pair of leaves, from the left. An odd last leaf goes up unchanged.
- 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:
tag MST14 bytesversion1 bytenumber4 bytesleaves2 bytesroot32 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:
- It is in a block with sufficient confirmations.
- It has exactly two outputs.
-
Output 0 has the value 0. Its script is
0x6a,0x2band a record of 43 bytes with the tagMST1and version 1. - Record 0 has a leaf count of 0. Each later record has one leaf or more.
A verifier examines a receipt in these steps:
- The verifier examines the format of the memo.
- The verifier calculates the leaf from the memo.
- The verifier calculates the root from the leaf and the path.
- The verifier gets the record transaction and makes sure that it is valid. It compares the root with the root in output 0.
- 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.
- The verifier does step 5 again for each record, back to record 0 of that chain.
- 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.
- 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.
- 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.
- The verifier reads the time of the block of the record transaction.
- 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:
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.
Wait