Monero 백서

Monero

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 19쪽 중 10쪽

uture miners. 41 The miner transaction output can theoretically be sent to a subaddress and/or use multisig and/or an encoded payment ID. We don’t know if any implementations have any of those features. CHAPTER 7. THE MONERO BLOCKCHAIN 70 60th block after it is published [21]. 42 Since RingCT was implemented in January 2017 (v4 of the protocol) [16], people downloading a new copy of the blockchain compute a commitment to the miner transaction (a.k.a. tx) amount src/block- chain db/ blockchain db.cpp add trans- action() a, as C = 1G +aH, and store it for referral. This allows block miners to spend their miner transaction outputs just like a normal transaction’s outputs, putting them in MLSAG rings with other normal and miner tx outputs. Blockchain verifiers store each post-RingCT block’s miner tx amount commitment, for 32 bytes each. 7.4 Blockchain structure Monero’s blockchain style is simple. It starts with a genesis message src/crypto- note core/ cryptonote tx utils.cpp generate genesis block() of some kind (in our case basically a miner transaction dispersing the first block reward), which constitutes the genesis block (see Appendix C). The next block contains a reference to the previous block, in the form of block ID. A block ID is simply a hash of src/crypto- note basic/ cryptonote format utils.cpp get block hashing blob() the block’s header (a list of information about a block), a so-called ‘Merkle root’ that attaches all the block’s transaction IDs (which are hashes of each transaction), and the number of transactions (including the miner transaction). src/crypto- note basic/ cryptonote format utils.cpp calculate block hash() 43 Block ID =Hn(Block header, Merkle root, #transactions + 1) To produce a new block, one must do proof of work hashes by changing a nonce value stored in the block header until the difficulty target condition is met. 44 The proof of work and block ID hash the same information, except use different hash functions. Blocks are mined get block longhash() by, while (PoW output∗difficulty )> 2256− 1, repeatedly changing the nonce and recalculating PoW output =HPoW (Block header, Merkle root, #transactions + 1) 7.4.1 Transaction ID Transaction IDs are similar to the message signed by input MLSAG signatures (Section 6.2.2), but include the MLSAG signatures too. The following information is hashed: 42 The miner tx can’t be locked for more or less than 60 blocks. If it is published in the 10 th block, its unlock height is 70, and it may be spent in the 70 th block or later. src/crypto- note core/ block- chain.cpp is tx spendtime unlocked() 43 +1 accounts for the miner tx. 44 In Monero a typical miner (from https://monerobenchmarks.info/ as of this writing) can do less than 50,000 hashes per second, so less than 6 million hashes per block. This means the nonce variable doesn’t need to be that big. Monero’s nonce is 4 bytes (max 4.3 billion), and it would be strange for any miner to require all the bits. CHAPTER 7. THE MONERO BLOCKCHAIN 71 • TX Prefix src/crypto- note basic/ cryptonote format utils.cpp calculate transa- ction hash() ={transaction era version (e.g. ringCT = 2), inputs {key offsets, key images}, outputs{one-time addresses}, extra{transaction public key, encoded payment ID, misc.}} • TX Stuff ={signature type (RCTTypeNull or RCTTypeBulletproof2), transaction fee, pseudo output commitments for inputs, ecdhInfo (encrypted or cleartext amounts), output commit- ments} • Signatures ={MLSAGs, range proofs} In this tree diagram the black arrow indicates a hash of inputs. Transaction ID Hn(TX Prefix) Hn(TX Stuff) Hn(Signatures) In place of an ‘input’, a miner transaction records the block height of its block. This ensures the miner transaction’s ID, which is simply a normal transaction ID except with Hn(Signatures)→ 0, is always unique, for simpler ID-searching. 7.4.2 Merkle tree Some users may want to discard data from their copy of the blockchain. For example, once you verify a transaction’s range proofs and input signatures, the only reason to keep that signature information is so users who obtain it from you can verify it for themselves. To src/crypto/ tree-hash.c tree hash() facilitate ‘pruning’ transaction data, and to more generally organize it within a block, we use a Merkle tree [92], which is just a binary hash tree. Any branch in a Merkle tree can be pruned if you keep its root hash. 45 An example Merkle tree based on four transactions and a miner transaction is diagrammed in Figure 7.1.46 45 The first known pruning method was added in v0.14.1 of the core Monero implementation (March 2019, co- inciding with protocol v10). After verifying a transaction, full nodes can delete all its signature data (including Bulletproofs, MLSAGS, and pseudo output commitments) while keeping Hn(Signatures) for computing the trans- action ID. They only do this with 7/8 ths of all transactions, so every transaction is fully stored by at least 1/8 th of the network’s full nodes. This reduces blockchain storage by about 2/3 rds. [55] 46 A bug in Monero’s Merkle tree code led to a serious, though apparently non-critical, real-world attack on September 4th, 2014 [86]. CHAPTER 7. THE MONERO BLOCKCHAIN 72 Merkle Root Hash B Transaction ID 1 Transaction ID 2 Hash C Transaction ID 3 Hash A Transaction ID 4 Miner Transaction ID Figure 7.1: Merkle Tree A Merkle root is inherently a reference to all its included transactions. CHAPTER 7. THE MONERO BLOCKCHAIN 73 7.4.3 Blocks A block is basically a block header and some transactions. Block headers record important in- formation about each block. A block’s transactions can be referenced with their Merkle root. We present here the outline of a block’s content. Our readers can find a real block example in Appendix B. • Block header: – Major version : Used to track hard forks (changes to the protocol). – Minor version : Once used for voting, now it just displays the major version again. – Timestamp : src/crypto- note core/ block- chain.cpp check block timestamp() UTC (Coordinated Universal Time) time of the block. Added by min- ers, timestamps are unverified but they won’t be accepted if lower than the median timestamp of the previous 60 blocks. – Previous block’s ID : Referencing the previous block, this is the essential feature of a blockchain. – Nonce : A 4-byte integer that miners change over and over until the PoW hash meets the difficulty target. Block verifiers can easily recalculate the PoW hash. • Miner transaction: Disperses the block reward and transaction fees to the block’s miner. • Transaction IDs: References to non-miner transactions added to the blockchain by this block. Tx IDs can, in combination with the miner tx ID, be used to calculate the Merkle root, and to find the actual transactions wherever they are stored. In addition to the data in each transaction (Section 6.3), we store the following information: • Major and minor versions: variable integers ≤ 9 bytes • Timestamp: variable integer≤ 9 bytes • Previous block’s ID: 32 bytes • Nonce: 4 bytes, can extend its effective size with the miner tx extra field’s extra nonce 47 • Miner transaction: 32 bytes for a one-time address, 32 bytes for a transaction public key (+1 byte for its ‘extra’ tag), and variable integers for the unlock time, corresponding block’s height, and amount. After downloading the blockchain, we also need 32 bytes to store an amount commitment C = 1G +aH (only for post-RingCT miner tx amounts). • Transaction IDs: 32 bytes each 47 Within each transaction is an ‘extra’ field which can contain more-or-less arbitrary data. If a miner needs a wider range of nonces than just 4 bytes, they can add or alter data in their miner tx’s extra field to ‘extend’ the nonce size. [81] Part II Extensions 74 CHAPTER 8 Monero Transaction-Related Knowledge Proofs Monero is a currency, and like any currency its uses are complex. From corporate accounting, to market exchange, to legal arbitration, different interested parties may want to know detailed information about transactions made. How can you know for sure that money you received came from a specific person? Or prove that you did in fact send a certain output or transaction to someone despite claims to the contrary? Senders and recipients in the Monero public ledger are ambiguous. How can you prove you have a certain amount of money, without compromising your private keys? Amounts in Monero are completely hidden from observers. We consider several types of transaction assertions, a few of which are implemented in Monero and available with built-in wallet tools. We also outline a framework for auditing the full balance owned by a person or organization, that doesn’t require leaking information about future transactions they might make. 8.1 Transaction proofs in Monero Monero transaction proofs are in the process of being updated [103]. The currently implemented proofs are all ‘version 1’, and don’t include domain separation. We describe only the most advanced proofs, whether they be currently implemented, slated for implementation in future releases [104], or hypothetical proofs that may or may not get implemented (Sections 8.1.5 [130], and 8.2.1). 75 CHAPTER 8. MONERO TRANSACTION-RELATED KNOWLEDGE PROOFS 76 8.1.1 Multi-base Monero transaction proofs There are a few details to be aware of going forward. Most Monero transaction proofs involve multi-base proofs (recall Section 3.1). Wherever relevant, the domain separator is Ttxprf 2 = Hn(“TXPROOF V2”).1 The message being signed src/wallet/ wallet2.cpp get tx proof() is usually (unless otherwise specified) m = Hn(tx hash, message ), where tx hash is the relevant transaction’s ID (Section 7.4.1), andmessage is an optional message that provers or third parties can provide to make sure the prover actually makes a proof and hasn’t stolen it. Proofs are encoded in base-58, a binary-to-text encoding scheme first introduced for Bitcoin [28]. Verifying these proofs always involves first decoding them from base-58 back to binary. Note that verifiers also need access to the blockchain, so they can use transaction ID references to get information like one-time addresses. 2 The structure of key prefixing in proofs is somewhat lopsided, due in part to accumulating updates that haven’t reorganized it. Challenges for 2-base ‘version 2’ proofs are assembled with this format, where if ‘base key 1’ is G then its position in the challenge is filled with 32 zero bytes, c =Hn(m, public key 2, proof part 1, proof part 2, Ttxprf 2, public key 1, base key 2, base key 1) 8.1.2 Prove creation of a transaction input ( SpendProofV1) Suppose we made a transaction, and want to prove it. Clearly, by remaking a transaction input’s signature on a new message, any verifier would have no choice but to conclude we made the original. Remaking all of a transaction’s inputs’ signatures means we must have made the entire transaction (recall Section 6.2.2), or at the very least fully funded it. 3 A so-called ‘SpendProof’ src/wallet/ wallet2.cpp get spend proof() contains remade signatures for all of a transaction’s inputs. Importantly, SpendProof ring signatures re-use the original ring members to avoid identifying the true signer via ring intersections. SpendProofs are implemented in Monero, and to encode one for transmission to verifiers, the prover concatenates the prefix string “ SpendProofV1” with the list of signatures. Note that the prefix string is not in base-58 and doesn’t need to be encoded/decoded, since its purpose is human readability. The SpendProof SpendProofs unexpectedly don’t use MLSAGs, but rather Monero’s original ring signature scheme src/crypto/ crypto.cpp generate ring signa- ture() that was used in the very first transaction protocol (pre-RingCT) [136]. 1 Just like in Section 3.6, hash functions should be domain separated by prefixing them with tags. The current Monero transaction proofs implementation has no domain separation, so all the tags in this chapter are in features not yet implemented. 2 Transaction IDs are usually communicated separately from proofs. 3 As we will see in Chapter 11, someone who made one input signature didn’t necessarily make all input signatures. CHAPTER 8. MONERO TRANSACTION-RELATED KNOWLEDGE PROOFS 77 1. Calculate key image ˜K =koπHp(Koπ). 2. Generate random number α∈R Zl and random numbers ci,ri∈R Zl for i∈{ 1, 2,...,n} but excluding i =π. 3. Compute ctot =Hn(m, [r1G +c1Ko1], [r1Hp(Ko1) +c1 ˜K],..., [αG], [αHp(Koπ)],..., etc.) 4. Define the real challenge cπ =ctot− n∑ i=1,i⁄=π ci 5. Define rπ =α−cπ∗koπ (mod l). The signature is σ = (c1,r 1,c 2,r 2,...,c n,rn). Verification To verify src/wallet/ wallet2.cpp check spe- nd proof() a SpendProof on a given transaction, the verifier confirms that all ring signatures are valid using information found in the relevant reference transaction (e.g. key images, and output offsets for getting one-time addresses from other transactions). 1. Compute ctot =Hn(m, [r1G +c1Ko1], [r1Hp(Ko1) +c1 ˜K],..., [rnG +cnKon], [rnHp(Kon) +cn ˜K]) 2. Check that ctot ?= n∑ i=1 ci Why it works Note how this scheme is the same as bLSAG (Section 3.4) when there is only one ring member. To add a fake member, instead of passing the challenge cπ+1 into a new challenge hash, the member gets added into the original hash. Since the following equation cs =ctot− n∑ i=1,i⁄=s ci trivially holds for any index s, a verifier will have no way to identify the real challenge. Moreover, without knowledge ofkoπ the prover would never have been able to definerπ properly (except with negligible probability). CHAPTER 8. MONERO TRANSACTION-RELATED KNOWLEDGE PROOFS 78 8.1.3 Prove creation of a transaction output ( OutProofV2) Now suppose we sent someone money (an output) and want to prove it. Transaction outputs contain at heart three components: the recipient’s address, the amount sent, and the transaction private key. Amounts are encoded, so we only really need the address and transaction private key to get started. Anyone who deletes or loses their transaction private key will be unable to make an OutProof, so in that sense OutProofs are the least reliable of all Monero transaction proofs. 4 Our task here is to show the one-time address was made from the recipient’s address, and allow verifiers to reconstruct the output commitment. We do so by providing the sender-receiver shared secret rKv, then proving we created it and that it corresponds with the transaction public key and recipient’s address by signing a 2-base signature (Section 3.1) on the base keys G and Kv. Verifiers can use the shared secret to check the recipient src/wallet/ wallet2.cpp check tx proof() (Section 4.2), decode the amount (Section 5.3), and reconstruct the output commitment (Section 5.3). We provide details for both normal addresses and subaddresses. The OutProof To generate src/crypto/ crypto.cpp generate tx proof() a proof for an output directed to an address ( Kv,Ks) or subaddress ( Kv,i,Ks,i), with transaction private key r, where the sender-receiver shared secret is rKv, recall that the transaction public key stored in transaction data is either rG or rKs,i depending on whether or not the recipient is a subaddress (Section 4.3). 1. Generate random number α∈R Zl, and compute (a) Normal address: αG and αKv (b) Subaddress: αKs,i and αKv,i 2. Calculate the challenge (a) Normal address:5 c =Hn(m, [rKv], [αG], [αKv], [Ttxprf 2], [rG], [Kv], [0]) (b) Subaddress: c =Hn(m, [rKv,i], [αKs,i], [αKv,i], [Ttxprf 2], [rKs,i], [Kv,i], [Ks,i]) 3. Define the response 6 rresp =α−c∗r. 4. The signature is σoutproof = (c,rresp). 4 We can think of an ‘OutProof’ as showing an output is ‘outgoing’ from the prover. The corresponding ‘InProofs’ (Section 8.1.4) show outputs that are ‘incoming’ to the prover’s address. 5 Here the ‘0’ value is a 32-byte encoding of zero bytes. 6 Due to the limited number of available symbols, we unfortunately usedr for both responses and the transaction private key. Superscript ‘resp’ for ‘response’ will be used to differentiate the two when necessary. CHAPTER 8. MONERO TRANSACTION-RELATED KNOWLEDGE PROOFS 79 A prover src/wallet/ wallet2.cpp get tx proof() can generate a bunch of OutProofs, and send them all together to a verifier. He con- catenates prefix string “ OutProofV2” with a list of proofs, where each item (encoded in base-58) consists of the sender-receiver shared secretrKv (orrKv,i for a subaddress), and its corresponding σoutproof . We assume the verifier knows the appropriate address for each proof. Verification 1. Calculate the challenge src/crypto/ crypto.cpp check tx proof() (a) Normal address: c′ =Hn(m, [rKv], [rrespG +c∗rG], [rrespKv +c∗rKv], [Ttxprf 2], [rG], [Kv], [0]) (b) Subaddress: c′ =Hn(m, [rKv,i], [rrespKs,i+c∗rKs,i], [rrespKv,i+c∗rKv,i], [Ttxprf 2], [rKs,i], [Kv,i], [Ks,i]) 2. If c =c′ then the prover knows r, and rKv is legitimately a shared secret between rG and Kv (except with negligible probability). 3. The src/wallet/ wallet2.cpp check tx key hel- per() verifier should check the recipient’s address provided can be used to make a one-time address from the relevant transaction (it’s the same computation for normal addresses and subaddresses) Ks ?=Kot−Hn(rKv,t ) 4. They should also decode the output amount bt, compute the output mask yt, and try to reconstruct the corresponding output commitment 7 Cbt ?=ytG +btH 8.1.4 Prove ownership of an output ( InProofV2) An OutProof shows the prover sent an output to an address, while an InProof shows an output was received to a certain address. It is essentially the other ‘side’ of the sender-receiver shared secretrKv. This time the prover proves knowledge of kv inKv, and that in combination with the transaction public key rG the shared secret kv∗rG appears. Once a verifier has rKv, they can check if the corresponding one-time address is owned by the prover’s address with src/wallet/ wallet2.cpp check tx proof() Ko−Hn(kv∗rG,t )∗G ?=Ks (Section 4.2.1). By making an InProof for all transaction public keys on the blockchain, a prover will reveal all his owned outputs. 7 A valid OutProof signature doesn’t necessarily mean the recipient considered is the real recipient. A malicious prover could generate a random view key K′v, compute K′s =Ko−Hn(rK′v,t )∗G, and provide (K′v,K′s) as the nominal recipient. By recalculating the output commitment, verifiers can be more confident the recipient address in question is legitimate. However, a prover and recipient could collaborate to encode the output commitment using K′v, while the one-time address uses ( Kv,Ks). Since the recipient would need to know the private key k′v (assuming the output amount is still meant to be spendable), there is questionable utility to that level of deception. Why wouldn’t the recipient just use ( K′v,K′s) (or some other single-use address) for the entire output? Since the computation of Cbt is related to the recipient, we consider the described OutProof verification process adequate. In other words, the prover can’t use it to deceive verifiers without coordinating with the recipient. CHAPTER 8. MONERO TRANSACTION-RELATED KNOWLEDGE PROOFS 80 Giving the view key directly to a verifier would have the same effect, but once they have that key the verifier would be able to identify ownership of outputs to be created in the future. With InProofs the prover is able to retain control of his private keys, at the cost of the time it takes to prove (and then verify) each output is owned or unowned. The InProof An InProof is constructed the same way as an OutProof src/crypto/ crypto.cpp generate tx proof() , except the base keys are now J = {G,rG}, the public keys areK ={Kv,rK v}, and the signing key is kv instead of r. We will show just the verification step to clarify our meaning. Note that the order of key prefixing changes ( rG and Kv swap places) to coincide with the different role each key has. A multitude of InProofs, related to many outputs owned by the same address, can be sent together to the verifier. src/wallet/ wallet2.cpp get tx pro
프로젝트로 돌아가기