Privacy Module
The Privacy module enables optional zkSNARK-based shielded transactions on RP1.
Overview
| Feature | Description |
|---|---|
| Proving System | Groth16 on BN254 |
| Hash Function | MiMC (ZK-friendly) |
| Anonymity Set | 11 (1 real + 10 decoys) |
| Proof Size | 256 bytes |
| Verify Time | ~2ms |
Operations
Shield Tokens
Convert public tokens to private:
rp1d tx privacy shield 1000000urp1 \
--from my-wallet \
--chain-id rp1-1
import { PrivacyModule } from '@rp1/sdk';
const privacy = new PrivacyModule(client);
const tx = await privacy.shield(wallet, '1000000', 'urp1');
Private Transfer
Transfer privately with ring signatures:
rp1d tx privacy transfer \
--recipient rp1recipient... \
--amount 500000urp1 \
--from my-wallet
const tx = await privacy.transfer(wallet, 'rp1recipient...', '500000');
Unshield Tokens
Convert private tokens back to public:
rp1d tx privacy unshield 500000urp1 \
--from my-wallet
const tx = await privacy.unshield(wallet, '500000', 'urp1');
Viewing Keys
Grant auditors access to view your transactions:
Create Viewing Key
rp1d tx privacy create-viewing-key \
--grantee rp1auditor... \
--type full \
--expiry "2025-12-31T00:00:00Z" \
--from my-wallet
Viewing Key Types
| Type | Can See |
|---|---|
full | All transactions and balances |
incoming | Only incoming transactions |
outgoing | Only outgoing transactions |
balance | Current balance only |
Revoke Viewing Key
rp1d tx privacy revoke-viewing-key \
--grantee rp1auditor... \
--from my-wallet
Query Commands
Get Shielded Balance
# With your spending key
rp1d query privacy balance --from my-wallet
List Viewing Keys
rp1d query privacy viewing-keys $(rp1d keys show my-wallet -a)
Pool Statistics
rp1d query privacy pool-stats
Message Types
MsgShield
message MsgShield {
string sender = 1;
cosmos.base.v1beta1.Coin amount = 2;
}
MsgPrivateTransfer
message MsgPrivateTransfer {
string sender = 1;
string recipient = 2;
bytes proof = 3;
bytes encrypted_amount = 4;
repeated bytes ring_members = 5;
}
MsgUnshield
message MsgUnshield {
string sender = 1;
cosmos.base.v1beta1.Coin amount = 2;
bytes proof = 3;
bytes nullifier = 4;
}
Parameters
| Parameter | Default | Description |
|---|---|---|
ring_size | 11 | Number of decoys + 1 |
min_shield_amount | 1000 | Minimum shield amount |
max_viewing_key_duration | 365 days | Max viewing key validity |
proof_verification_gas | 200000 | Gas for proof verification |
Events
// Emitted on shield
EventTypeShield = "privacy_shield"
AttributeKeyAmount = "amount"
AttributeKeyCommitment = "commitment"
// Emitted on transfer
EventTypePrivateTransfer = "privacy_transfer"
AttributeKeyNullifier = "nullifier"
// Emitted on unshield
EventTypeUnshield = "privacy_unshield"
AttributeKeyRecipient = "recipient"
Security Considerations
- Note Storage: Keep your spending key secure - it's required to spend shielded tokens
- Viewing Keys: Only grant to trusted parties; revoke when no longer needed
- Timing: Avoid shielding immediately before spending for better anonymity
- Amount Patterns: Use standard amounts to improve mixing
- Decoy Selection: Let notes age for better anonymity set
Gas Costs
| Operation | Gas | Approximate Cost |
|---|---|---|
| Shield | 200,000 | ~$0.0002 |
| Transfer | 350,000 | ~$0.00035 |
| Unshield | 200,000 | ~$0.0002 |
| Create Viewing Key | 50,000 | ~$0.00005 |