Railgun 백서

Railgun

원문

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

underlying blockchain on RAILGUN privacy users’ behalf. Actions coming from 0zk addresses appear to originate from Broadcaster addresses. As they are simply a 0x address, anyone can theoretically be a Broadcaster. Broadcasters run a micro Node.Js that broadcasts gas to Broadcaster Clients (i.e. wallets equipped with RAILGUN). Broadcasters also automatically process interactions when received. When users send an interaction in RAILGUN, they select an appropriate Broadcaster, typically based on low gas and availability. The interaction is encrypted in transit, and its contents cannot be read by the Broadcaster, except for an amount of gas which is packaged to allocate to the Broadcaster’s services. Upon receipt of a interaction, the selected Broadcaster will validate its packaged supply and submit the interaction to the underlying blockchain network. Through submitting the interaction, the Broadcaster obscures the sender, amount, receiver, and token details. This makes interactions confidential so they cannot be associated with the sender’s 0x public address. NOTE: At no point do Broadcasters custodially hold users’ tokens nor do they confirm interactions themselves, they merely transfer encrypted information for confirmation by the underlying blockchain infrastructure. Broadcasters are also unable to decrypt details about the interactions, nor can they change the details of an interaction as changing any information would lead to an invalid hash and be rejected by the system as an incorrect cryptographic proof. The Broadcaster network is robust from a game theory perspective. If a user’s chosen Broadcaster refuses to pass on an interaction for whatever reason, then they can send it to another cooperative Broadcaster. All that it takes is for at least 1 cooperative Broadcaster to submit the data on-chain for the underlying blockchain’s ledger to update. ### Waku Network Broadcasters communicate with users through the [Waku ](https://waku.org/)peer-to-peer private communication network. Waku is a decentralized messaging protocol with strong privacy preservation such as sender confidentiality, metadata protection, and secure personally identifiable information. #### How Does RAILGUN use Waku? Waku connects Broadcasters with users to broadcast gas supplies and inform Broadcasters that they wish to have an interaction broadcasted. **Transaction Broadcasts** All interactions that require a Broadcaster generate an additional note addressed to the selected Broadcaster using the Broadcaster's public key. Transaction data is then encrypted and broadcast to the Broadcaster network through the `transact()` function. The user's client then encrypts their transaction data with a shared key derived from the Broadcaster's public key and a randomly generated private key. Broadcasters then attempt to decrypt every message on the chain's where they are listening for messages. Any messages that can be decrypted by a Broadcaster are thus addressed to them. If such a note is found and can be decrypted by the Broadcaster, they verify that the value and token of the note match a previously advertised rate \* the estimated gas of the transaction. Once an acceptable gas submission is included in the transaction, the Broadcaster signs and submits the transaction for consensus by the underlying blockchain. #### Interaction Response The Broadcaster then broadcasts the success/failure status of the transaction in an encrypted message over Waku through the `transact-response.json` file. This status message is encrypted using the shared key derived in the earlier transaction broadcast stage. The client listens to the `transact-response.json` content topic for any message they can decrypt using the previously randomly generated private key. In the event of failure, the transaction sender can retry with the same Broadcaster or select a new Broadcaster. # Privacy Overview How RAILGUN's ZK proofs and Broadcasters keep transactions private without any custodian. With this knowledge of [ZK proofs and zk-SNARKs](https://docs.railgun.org/wiki/learn/privacy-system/zero-knowledge-cryptography), we can see how RAILGUN maintains privacy. Users can prove they can spend tokens without needing to share what those tokens are and how much they have of it. Broadcasters and the privacy set then enhance the data confidentiality for senders and recipients of interactions such that no identifiable information is compromised at any stage in the process. To use an old-world analogy, RAILGUN users are writers of letters, ZK proofs fact check the contents of the letters, RAILGUN smart contracts are a sealed envelope, and Broadcasters are mailmen. All an outside observer can see is that a letter has been posted, but they would have no visibility as to what is in the letter or who has sent it. RAILGUN is **not** a safe, vault, or deposit box. Those imply a party holding your funds somewhere. RAILGUN is non-custodial, and no one, including RAILGUN contributors, ever holds user funds.&#x20; <figure><img src="https://4189133001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MgpI5FGDnzf3cR6tzx7%2Fuploads%2Ft7FMVUqCN90NdQTskJuf%2Frailgun_flowchart_-02.png?alt=media&#x26;token=521dfa7b-0746-4d5c-a9ef-b32ef1d690b0" alt=""><figcaption></figcaption></figure> # Wallets and Keys How RAILGUN's 0zk addresses, Spending Keys, and shareable Viewing Keys work. RAILGUN wallets (and by extension 0zk addresses/keys) can be created by any wallet infrastructure linked to the RAILGUN SDK. The first such wallet is the [Railway Wallet](https://railway.xyz/), developed by a partner project of RAILGUN. The RAILGUN SDK follows the BIP-32 standard for key derivation from a seed, which allows for [hierarchical deterministic wallets ](https://river.com/learn/terms/b/bip-32/)along an elliptic curve. To learn more about key derivation standards: \- For bip32, start [here](https://trezor.io/learn/a/what-is-bip39) with bip39 mnemonics for how seed phrases work. \- [Here](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) for the method to take the randomness the seed phrase represents and derive keys from it, being bip32. \- [SLIP-44](https://github.com/satoshilabs/slips/blob/master/slip-0044.md) which defines standard paths that wallets derive along to get the key for a particular coin. Users have access to 2 kinds of keys in their RAILGUN wallets: 1. Spending Key – The key that allows users to cryptographically prove they own their tokens and send interactions. Spending Keys are analogous to a regular cryptocurrency wallet private key, only with a private 0zk address. 2. Viewing Key – A key that exclusively allows viewing of all interactions (including private ones) sent by a particular address. Users can define the beginning and ending block for which the Viewing Key can observe in a scoped way. This is useful for auditability purposes, for example, a user can define the beginning and end of a tax year for their Viewing Key by block number. Both the public Viewing Key and Spending Key are encoded in the 0zk address, hence why private addresses on RAILGUN are longer than standard 0x addresses. The key generation method is identical to how most other crypto keys are generated. Private keys are of course, not shared publicly at any stage in wallet generation nor are they shared with any components of the RAILGUN system such as provers, verifiers, or Broadcasters. 0zk is the only valid RAILGUN private address format. RAILGUN is a Layer 1 smart-contract system, not a rollup, so there is no "rollup address." RAILGUN does not use "rg1"-prefixed addresses today. ### Spending Keys Spending Keys are generated along the [Baby Jubjub elliptic curve, ](https://eips.ethereum.org/EIPS/eip-2494)which is a zk-SNARK-friendly elliptic curve, and follows the BIP-32 standard. Zk-SNARK proof verification on a blockchain requires the embedding of an elliptic curve inside a zk-SNARK circuit to enable succinctness and to fit within a block gas limit. Baby Jubjub enables efficient cryptographic functions to be built on-chain. ### Viewing Keys Viewing Keys are implemented on Edwards-curve Digital Signature Algorithm [(EdDSA) ](https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm)curves, specifically Ed25519. Viewing Keys enable the holder to decrypt the encoded interaction information but not send interactions. They merely scan the RAILGUN smart contract events to reveal what has been sent to users and what interactions users have sent. A different key derivation scheme is used for viewing keys as Ed25519 is more efficient if no zk-SNARK circuits need to be used. Unlike the Spending Key, the Viewing Key is designed to be shareable. You can generate a view-only credential and give it to a third party, such as an auditor, a tax tool, or a business partner, so they can see your balances and history with zero ability to spend your funds. Sharing a Viewing Key does not put your funds at risk. Only sharing a Spending Key does. See [View-Only Wallets](https://docs.railgun.org/developer-guide/wallet/private-wallets/view-only-wallets) for how to generate one. **NOTE:** *Once a Viewing Key is generated, they are irrevocable, meaning that whoever holds the key can see private interactions forever. An upcoming update will allow Viewing Keys to be scoped by block number, i.e. only display interactions from Block Number X to Block Number Y.* # Shielding Tokens The first step in using the RAILGUN Privacy System is to privatize cryptocurrency tokens. Shielding is the process whereby tokens enter the wallet’s private 0zk address from the public 0x address. Once tokens are in the 0zk address, users can send, swap, and interact with DeFi privately. Further, any token that exists on the public blockchain can be shielded, which would include any ERC-20 token as well as ERC-721 NFTs. Users initiate shielding by sending a shield interaction which contains public data (the token, the amount, and other values called) from their public wallet. The RAILGUN smart contracts then take these values and computes a commitment (called a note). Notes are a hashed value of the public data sent by the user at the start of the shielding process. The hashed value of a note (a circuit output) cannot be reversed to show the original value (an input). Inputs and outputs in this context are the interaction/token data. ### RAILGUN Smart Contract: *shield()* When a user initiates a shielding interaction, they call the Solidity function, `shield()`. This function includes everything required to shield assets into the RAILGUN privacy system, including the Poseidon hash function for encrypting notes. The Merkle Tree to which new notes are committed is also stored in the smart contract storage in variables called `merkleRoot` and `merkleLeaf`, and is handled by the `Commitments`.`sol` contract. The `shield()` function emits the `Shield` event upon completion. Events within the RAILGUN smart contract contain data within them. Due to RAILGUN’s hashing functions and zk-SNARK proving systems, this data can only be read by the holder of either the Spending Key or Viewing Key, preserving privacy each time the smart contract is called. For developers integrating RAILGUN SDK, the `shield()` function and anything related to shielding tokens will not require specific integration efforts as the SDK will abstract all encryption and interaction generation functions. ### RAILGUN Smart Contract: transact() Spend transactions call the `transact()` function. This function is used to interact with your private balance in a number of ways. This is accomplished by verifying that the Nullifiers in the internal Merkle Tree path correspond to the circuit-inputs and number of circuit-outputs being spent. Essentially, this function feeds to a zk-SNARK proof to ensure that the number of inputs matches the number of outputs on the circuit, and enforces the rule that Nullifiers must not have been seen anywhere on the Merkle Tree before. If these nullifiers have been seen before, it is then verified that this is not a valid spend transaction and the user does not have the requisite UTXOs (insufficient funds) to send the transaction. ### Private Pools & Merkle Trees <figure><img src="https://4189133001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MgpI5FGDnzf3cR6tzx7%2Fuploads%2FeWPHFEiEaq9EdPDmWcVD%2FHash.png?alt=media&amp;token=074fae6e-2794-4ae4-8ca9-a14e77f9eb59" alt=""><figcaption><p>Merkle Tree data structure, the Root (top level) is a hash of all the corresponding leaves (everything below the top level)</p></figcaption></figure> Once tokens are shielded by the cryptographic methods described above, they’re added to the privacy set in the RAILGUN smart contract. The RAILGUN system contains an efficient internal implementation of a batch-incremental Merkle Tree. Each shield interaction generates a new note which takes the form of a new Root/Leaf on the Merkle Tree. All tokens within the RAILGUN system share the same Merkle Tree. Every interaction that updates the state of the Merkle Tree will generate a new Merkle Root/Leaf that is hashed and secured by the zk-SNARK circuits. During the shielding process, the RAILGUN smart contract requires the amount and sending wallet address. This means that the sender of a `shield` interaction’s public key is broadcast to the wider blockchain network. However, this is a regular blockchain interaction and not a centralized retrieval of the public key and is necessary to send tokens from the public ledger. Shields and Unshields are the only types of RAILGUN interactions that contain public information as they interact directly with public addresses. Once the appropriate proofs and notes have been added to the RAILGUN smart contract Merkle Tree, privacy is achieved. Interactions appear to originate from a Broadcaster, and therefore technically-speaking can have come from anyone in the private pool who has sufficient tokens to send the UTXO associated with the transaction. What’s more, all identifying information such as the amount of transactions are not shown in block explorers. ### Shielding NFTs The RAILGUN smart contracts supports the shielding of ERC-721 non-fungible tokens. Users are able to add NFTs to their private balance in order to protect the source of NFTs. This creates interesting integration possibilities, like the private auctioning of popular NFTs. But NFTs are much larger than merely JPEG images of primates. Many DeFi protocols, like Uniswap v3, which issues NFTs to represent LP positions. With the integration of NFTs into RAILGUN, users are able to safeguard NFTs in order to: * Auction NFT assets to private buyers * Provide liquidity privately on Uniswap v3 # Using Private Tokens RAILGUN’s interaction system is similar to the Bitcoin network’s, with the notable exception that everything is privatized by ZK proofs. The Merkle Tree keeps track of all balances held by 0zk addresses in the system which can only be updated if proof that passes the cryptographic validation rules is submitted to the RAILGUN smart contracts. ### UTXOs & Nullifiers RAILGUN operates on a [(U)TXO (unspent transaction output) model](https://academy.binance.com/en/glossary/unspent-transaction-output-utxo), (U) is in brackets as transaction outputs are completely secure from outside observers. Each UTXO is an encrypted note of a public key that establishes who can spend the underlying asset, amount, token ID, and a randomness field to maintain encryption. The output of RAILGUN circuits are UTXOs and Nullifiers, which is a hash generated from private keys that cannot be linked to a UTXO by anyone who is not a party to the transaction. Nullifiers are deterministically generated to further guard against double spends - put simply, they nullify a UTXO and disallow it from being spent again in the system. Nullifiers (and therefore circuit outputs) are calculated by a hash of the Spending Key combined with path indices of the Merkle Root/Leaf note, meaning that each note will always generate a unique Nullifier. The party holding the Spending Key is the only actor who can link which Nullifier as belonging to a corresponding UTXO. This also means that Broadcasters cannot change the transaction values, such as amount or destination address, without rendering the hash and note invalid and therefore failing the ZK proof checks. With RAILGUN’s zk-SNARK circuits, users can mathematically prove that they have valid UTXOs and therefore prevent double spend or false transactions whilst not showing any underlying information. Once all the cryptographic validation tests are passed, the Broadcaster will then submit the note to the blockchain for consensus and confirmation and the spend transaction is complete. ### RAILGUN Smart Contract: *transact()* Spend transactions call the transact() function. This function is used to interact with your private balance in a number of ways. This is accomplished by verifying that the Nullifiers in the internal Merkle Tree path correspond to the circuit-inputs and number of circuit-outputs being spent. Essentially, this function feeds to a zk-SNARK proof to ensure that the number of inputs matches the number of outputs on the circuit, and enforces the rule that Nullifiers must not have been seen anywhere on the Merkle Tree before. If these nullifiers have been seen before, it is then verified that this is not a valid spend transaction and the user does not have the requisite UTXOs (insufficient funds) to send the transaction. The `transact()` function emits the following events which are triggered when the RAILGUN contract detects any balance changes in the system: * `CommitmentBatch` – New zk-SNARK circuit outputs (i.e. new notes) occurring from the send transaction and transact() call. * `Nullifiers` – Private double spend markers that nullify the zk-SNARK circuit inputs used in the send transaction to ensure the UTXOs cannot be used again. For the purposes of integration, only a surface level understanding of the `transact()` function is required to integrate the RAILGUN SDK as the SDK again, and handles the computation on the integrating dApp’s behalf. For RAILGUN transactions to execute, some publicly observable input data will be broadcast to the wider blockchain network. These hashed public inputs are used to represent and validate outputs from the zk-SNARK circuits. This input data is always hashed and cannot be unencrypted by anyone who is not a party to the transaction. Hashing means that whilst the hashed values can be seen, no outside observer can reverse the hashing algorithm to arrive at the unencrypted input data, maintaining complete privacy throughout. The RAILGUN `transact()` function has the following public inputs: * `merkleRoot` * Any previous Merkle Root from the entire Merkle Tree. The RAILGUN smart contract computes a new Merkle Root each time funds are transferred. This does not need to be the newest Merkle Root, rather it is a race condition for the first Merkle Root picked up by the function. * `boundParamsHash` * Each dApp integrated with RAILGUN has its own unique parameters. Due to the constraints of circuit design, i.e., all circuits must be fixed before computation, this hash is computed at the user side for each required parameter instead of designing a custom circuit for each parameter. * Hash of the following values: * `formattedRandom` – Randomization factor to preserve security in hashing * `requireSuccess` – Boolean value that requires the contract call to be successful before progressing * `minGas` – Minimum amount of gas to be supplied to the transaction * `to/value/datanullifiers[nInputs]` – Nullifiers for the input notes * `nullifiers [nInputs]` * Nullifiers themselves are also hashed values. This public input is used to nullify the UTXO being sent in the transaction
프로젝트로 돌아가기