EToken Program
Description of EToken program and functions defined within it
Overview
The EToken Program work as a wrapper program on top of existing token program. It contains methods which enables transfer, minting, burning of encrypted tokens.
Encrypted Data Types
-
Euint64: Encrypted 64-bit unsigned integer representing token amounts
pub struct Euint64 { pub handle: u128, pub proof: Vec<u8>, pub ctx: Vec<u8>, } -
EAddress: Encrypted address representation for anonymous transfers
pub struct EAddress { pub handle: u128, } -
Ebool: Encrypted boolean for conditional operations
pub struct Ebool { pub handle: u128, } -
Einput: Generic encrypted input that can be converted to other types
pub struct Einput { pub handle: u128, pub proof: Vec<u8>, }
Account Types
-
EMint: Encrypted mint account storing token metadata and supply
pub struct EMint { pub mint: Pubkey, // Associated SPL token mint pub authority: Pubkey, // Mint authority pub supply: u64, // Total supply (plaintext) pub decimals: u8, // Token decimals pub is_initialized: bool, // Initialization status pub freeze_authority: Option<Pubkey>, // Freeze authority pub is_frozen: bool, // Freeze status } -
ETokenAccount: Encrypted token account storing user balances (created for every user)
pub struct ETokenAccount { pub mint: Pubkey, pub owner: Pubkey, pub amount: Euint64, pub delegate: Option<Pubkey>, pub is_initialized: bool, pub is_frozen: bool, }
Functions and Use Cases
initialize_mint
- Params
- decimals:
u8 - authority:
Pubkey
- decimals:
- Purpose: Creates a new encrypted token mint account for a given SPL token.
- Use Case: Initializes account for a certain mint address
- Process
- Creates an EMint PDA with seeds [b"emint", mint.key()]
- Sets up mint metadata (decimals, authority, freeze authority)
- Initializes supply to 0
- Sets freeze authority to the provided authority
initialize_account
- Params
- owner:
Pubkey
- owner:
- Purpose: Creates a new encrypted token account for a user which will hold encrypted tokens (pointer) for certain token for user.
- Use Case: Intializes account for user to store encrypted token pointers.
- Process:
- Creates an ETokenAccount PDA with seeds [b"eaccount", emint.key(), owner]
- Initializes with zero encrypted balance using Euint64::balance_handle()
- Sets owner and mint association
- Initializes delegate as None
- Only payer can initialize
mint_to
- Params
- to:
Pubkey- Recipient account owner - amount:
u64- Amount to mint (plaintext)
- to:
- Purpose: Mints encrypted tokens to a user's account.
- Process:
- Converts plaintext amount to encrypted
Euint64 - Adds encrypted amount to recipient's balance using homomorphic addition
- Updates mint supply
- Sets access control for the new balance
- Enforces maximum supply limit (1 billion tokens)
- Converts plaintext amount to encrypted
burn
- Params
- to:
Pubkey- Account owner (for access control) - amount:
Einput- Encrypted amount to burn
- to:
- Purpose: Burns encrypted tokens from a user's account.
- Process:
- Verifies that the user has sufficient balance using encrypted comparision (
le (less equal)) - Subtracts encrypted amount using (
PET.sub) - Updates account balance
- Sets access control for the new balance
- Returns the actual burned amount
- Verifies that the user has sufficient balance using encrypted comparision (
etransfer
- Params
- receiver:
Pubkey- Recipient account owner - amount:
Einput- Encrypted amount to transfer
- receiver:
- Purpose: Transfers encrypted tokens between accounts.
- Process:
- Verifies sender has sufficient balance.
- Performs encrypted subtraction from sender using
PET.sub. - Performs encrypted addition to receiver using
PET.add. - Updates both account balances for both sender and receiver account.
- Sets access control for both accounts.