Shield & Unshield: How RAILGUN Protects Your Tokens
In the first article, we covered why on-chain privacy matters and how RAILGUN brings it to DeFi. Now let's get practical. How do you actually make your tokens private? What happens under the hood when you shield and unshield?
In the first article, we covered why on-chain privacy matters and how RAILGUN brings it to DeFi. Now let's get practical. How do you actually make your tokens private? What happens under the hood when you shield and unshield?
## The Shield Process: Going Private
Shielding is your entry point into RAILGUN's private system. When you shield tokens, you're essentially depositing them into the RAILGUN smart contract while generating an encrypted record that only you can access.
Here's the flow:
**Step 1: Connect Your Public Wallet**
You start with a regular 0x address on Ethereum, Polygon, BSC, or Arbitrum. This is your public wallet that everyone can see on block explorers.
**Step 2: Generate Your 0zk Address**
Your 0zk address is your private identity within RAILGUN. Unlike 0x addresses, 0zk addresses are derived from a spending key that only you control. One spending key can generate unlimited 0zk addresses, and nobody can link them together unless you reveal the connection.
Think of 0zk addresses like stealth addresses in traditional finance. Each one is unique, unlinkable, and completely under your control.
**Step 3: Execute the Shield Transaction**
When you shield tokens, you send them from your 0x address to the RAILGUN smart contract. The contract:
1. Receives your tokens
2. Creates an encrypted UTXO (Unspent Transaction Output) representing your balance
3. Adds this UTXO to the Merkle Tree that tracks all private balances
4. Emits an encrypted event that only your spending key can decrypt
From this moment, your tokens are private. The blockchain shows that tokens went into the RAILGUN contract, but nobody can see your balance, who you transact with, or what you do next.
## Understanding 0zk Addresses
Your 0zk address isn't just a random string. It's cryptographically derived from your spending key and contains two components:
**Viewing Key** allows read-only access to your transactions. You can share this with accountants, auditors, or tax authorities without giving them control over your funds.
**Spending Key** gives full control. This is what you need to actually move your tokens. Guard it like you guard your seed phrase.
This separation is powerful. You can prove your transaction history for compliance without exposing your ability to spend.
## The Fee Structure: 0.25%
RAILGUN charges a 0.25% fee on both shielding and unshielding transactions. This fee goes to the RAILGUN DAO treasury and is distributed to RAIL stakers as Active Governor Rewards.
Some key points about fees:
- The 0.25% applies to shield and unshield actions only
- Private-to-private transfers within RAILGUN have no protocol fee
- You'll still pay normal network gas fees for transactions
- Fees can be paid in wrapped base tokens (WETH, WBNB, WMATIC) or stablecoins
This structure means the cost of privacy is minimal, especially for users who stay within the private system for extended periods. Once inside, you can transact freely without additional protocol fees.
## Private Transactions: The Hidden Economy
Once your tokens are shielded, you enter RAILGUN's private economy. Here's what you can do:
**Private Transfers** allow you to send tokens to any 0zk address. The sender, recipient, and amount are all hidden from public view.
**Private Swaps** let you trade tokens while keeping your activity confidential. RAILGUN integrates with existing DEXs like Uniswap and others, routing your trades through the privacy layer.
**Private DeFi Interactions** enable you to lend, borrow, provide liquidity, and more. The RAILGUN Relay system handles these interactions while maintaining your privacy.
All of this happens on-chain, verified by zero-knowledge proofs, without any centralized intermediary.
## The Unshield Process: Going Public Again
Sometimes you need to move tokens back to the public world. Maybe you're paying for something that requires a public address, or you want to use a protocol that doesn't support private transactions yet.
Unshielding reverses the process:
**Step 1: Initiate Unshield**
You specify how much to unshield and the destination 0x address. This can be any address, not just your original one.
**Step 2: Generate Proof**
Your wallet generates a zero-knowledge proof showing you have the right to spend the private tokens without revealing your full balance or transaction history.
**Step 3: Execute Transaction**
The RAILGUN contract verifies your proof, burns your private UTXOs, and sends the tokens to your specified public address.
Important: The unshield transaction shows tokens coming from the RAILGUN contract to a public address. While observers can see this specific movement, they cannot trace it back to your original shield transaction or see your private activity in between.
## Privacy Best Practices
To maximize your privacy, consider these practices:
**Use fresh addresses for unshielding.** Don't unshield to the same address you shielded from. This creates obvious links.
**Stay private longer.** The more time passes and the more activity happens in the RAILGUN pool, the larger your anonymity set becomes.
**Shield round numbers carefully.** If you shield exactly 1,847.23 tokens and later unshield exactly 1,847.23 tokens, the amounts might be linkable. Consider breaking up transactions.
**Use multiple 0zk addresses.** Just like you might use multiple wallets for different purposes, you can use multiple 0zk addresses to compartmentalize your private activity.
## What's Actually Happening On-Chain?
Let me break down what observers see at each step:
**During Shield:** "Address 0x123... sent 100 USDC to RAILGUN contract"
**During Private Activity:** Nothing. Zero. The blockchain sees no transactions because everything happens within the encrypted UTXO system.
**During Unshield:** "RAILGUN contract sent 50 USDC to address 0x456..."
The critical insight is that there's no visible connection between the shield and unshield. As far as blockchain observers know, these could be completely unrelated users.
## The Bottom Line
Shielding and unshielding are your gateways between public and private DeFi. The process is straightforward:
1. Shield tokens to enter the private system
2. Transact freely within RAILGUN without leaving traces
3. Unshield when you need to return to the public world
The 0.25% fee is a small price for genuine on-chain privacy, especially when you consider that private-to-private transactions are free.
In the next article, we'll dive into the cryptography that makes all of this possible. How do zero-knowledge proofs actually work? What are zk-SNARKs, and how does RAILGUN use them to verify transactions without revealing anything about them?
Get ready for some fascinating mathematics.