Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article covers Avalanche's Encrypted ERC.

The explanation is based on the following official documentation.

The following Zenn book covers the technical details in greater depth and is a useful follow-up to this article.

What is Encrypted ERC?

Encrypted ERC is a privacy-focused token mechanism compatible with ERC20 tokens. Anyone can inspect balances and transaction histories for ordinary ERC20 tokens. Encrypted ERC uses cryptographic techniques such as zero-knowledge proofs to prove that balances and transfer amounts are processed correctly without revealing those values.

It protects information that individuals and businesses wish to keep confidential while retaining the verifiability of a blockchain.

However, extensive privacy protection may raise concerns regarding anti-money laundering (AML) and countering the financing of terrorism (CFT). To address this, eERC introduces privileged decryption keys called Auditor Keys, which are held by designated auditors. This allows transaction contents to remain confidential under normal circumstances while authorized auditors can inspect individual transactions.

Encrypted ERC overview

Encrypted ERC combines smart contracts with zero-knowledge circuits (ZK circuits). Account balances and transfer amounts are handled in encrypted form and can be verified publicly. There are two operating modes.

Overview of Encrypted ERC

Standalone Mode

Used when issuing a new private token from scratch. A private token can be issued with a configured ERC20 token name and symbol.

  • Private Minting Issues new tokens without revealing the issued amount or confidential transaction details.
  • Private Burning Burns tokens without revealing the burned amount or confidential transaction details (the original explanation describes burning as sending tokens to the zero address).

Converter Mode

Used to apply privacy features to an existing ERC20 token. The underlying token itself remains unchanged; users can convert it into an encrypted representation.

  • Deposit Converts existing ERC20 tokens into encrypted tokens, keeping the resulting balance confidential.
  • Withdraw Converts private tokens back into the original ERC20 tokens.

Internal structure

Encrypted ERC uses several circuits for zero-knowledge proofs, including the following.

  • Registration Circuit A circuit verifying that a public key was correctly derived from a private key.
  • Transfer Circuit A circuit verifying that a transfer is correct while keeping the balance confidential. It also produces encrypted messages for the recipient and auditor.
  • Mint Circuit A circuit for minting new tokens without revealing the minted amount.
  • Burn Circuit A circuit for burning tokens without revealing the burned amount.
  • Withdraw Circuit A circuit proving that sufficient balance exists when converting private tokens back into the original ERC20 tokens.

Cryptography and privacy protection

  • Elliptic-curve cryptography (BabyJubjub) An efficient elliptic curve used in applications such as ZK proofs.
  • ElGamal encryption An asymmetric encryption scheme that enables calculations and transfers on encrypted user balances.
ElGamal encryption

ElGamal encryption

ElGamal is a public-key encryption scheme. Its security relies on the difficulty of the discrete logarithm problem.

Discrete logarithm problem

Given gg and yy, finding an exponent xx such that 𝑔𝑥=𝑦𝑔^𝑥 = 𝑦 in the relevant finite group is computationally difficult. This computational difficulty underpins the security of the scheme.

Characteristics

  • Uses public and private keys for encryption and decryption. The sender encrypts a message using the recipient's public key, and the recipient decrypts it with their private key.

  • Randomness produces different ciphertexts even for the same message. For example, encrypting an amount of 100 tokens produces a different ciphertext when fresh randomness is used. This makes it difficult to infer the plaintext from the ciphertext.

  • Additive homomorphism The encrypted-balance construction supports combining values without decrypting them. For example, encrypted balances can be added together or updated after a transfer.

    https://note.com/tesso57/n/n9070136d9426

Components

  • A large prime pp A prime number is divisible only by 1 and itself.
  • Generator gg Repeated multiplication (exponentiation) of gg generates elements of the relevant multiplicative group modulo pp.
  • Private key xx A large number known only to its owner.
  • Public key y=gx mod py = g^x \bmod p A publicly available value calculated from the private key.
  • Random value kk A fresh secret random value selected by the sender for each message. It affects the ciphertext and makes encryption nondeterministic. Because kk changes each time, encrypting the same message need not produce the same ciphertext.

Procedure

Key generation

  1. The sender and recipient agree on a large prime pp and a generator gg.
  2. The recipient (Alice, for example) selects a random private key xx, computes y=gx mod py = g^x \bmod p, and publishes it as the public key.

Encryption

  1. The sender (Bob, for example) represents the message to encrypt as a number mm.

  2. Bob selects a random ephemeral value kk, computes the following values, and sends the ciphertext (c1,c2)(c_1, c_2) to Alice.

    • c1=gk mod pc_1 = g^k \bmod p
    • c2=m×yk mod pc_2 = m \times y^k \bmod p

Decryption

  1. Alice uses her private key xx to compute s=c1x mod ps = c_1^x \bmod p and recover the original message m=c2×s−1 mod pm = c_2 \times s^{-1} \bmod p, where s−1s^{-1} is the modular inverse of ss.

The important point is that fresh random kk values produce different ciphertexts even when the message is the same.

Multiplicative inverse

A value that produces 1 when multiplied by another value in the relevant arithmetic system. For a number a, a number b satisfying the following equation is the multiplicative inverse of a.

a×b≡1(modp)a \times b \equiv 1 \pmod{p}

  • a = 3
  • p = 7

In the example above, 5 is the inverse of 3.

Using the modular inverse makes it possible to recover the original message mm from the ciphertext.

ElGamal encryption example

Note: Real cryptographic implementations use much larger numbers.

  • p=23p = 23, g=5g = 5
  • Alice's private key x=6x = 6
  • Public key y=56 mod 23=15625 mod 23=8y = 5^6 \bmod 23 = 15625 \bmod 23 = 8

Suppose Bob wants to send the message m=13m = 13.

  • Randomly select k=10k = 10.

    • c1=510 mod 23=9c_1 = 5^{10} \bmod 23 = 9
    • c2=13×810 mod 23=13×3 mod 23=17c_2 = 13 \times 8^{10} \bmod 23 = 13 \times 3 \bmod 23 = 17

Send ciphertext (9,17)(9, 17). Alice can recover the original 13 using the following calculation.

  • s=96 mod 23=3s = 9^6 \bmod 23 = 3
  • s−1=8s^{-1} = 8 (multiplicative inverse modulo 23)
  • m=17×8 mod 23=136 mod 23=13m = 17 \times 8 \bmod 23 = 136 \bmod 23 = 13
  • Poseidon hash A lightweight hash function optimized for zero-knowledge proofs, used in constructions such as encryption of verification records.
Poseidon hash

What is the Poseidon hash?

A hash function optimized for zero-knowledge proofs (ZKPs). It is designed to require far fewer constraints than conventional SHA256 or Keccak implementations in proof systems such as zkSNARKs. Conventional hash functions such as SHA256 operate on bit-oriented inputs, whereas Poseidon performs computations over finite fields. This difference reduces the complexity of proof circuits.

A constraint here is an equation or mathematical rule establishing that a computation was performed correctly. A ZK circuit consists of a set of such constraints.

Finite field

Here, this refers to the set of integers represented by their remainders modulo a large prime pp. For example, with prime p=97p = 97, the elements range from 00 to 9696, with 97≡097 ≡ 0 and 98≡198 ≡ 1.

Addition and multiplication produce results in the range from 00 to p−1p-1 after modular reduction, without requiring conventional overflow handling inside the field. In ZK circuits, finite-field addition and multiplication can require far fewer constraints than bitwise operations.

Algorithm

Poseidon is a hash function based on a sponge construction. A sponge construction applies permutations between the absorption of input data and the squeezing of hash outputs.

Internal state

  • An array whose number of elements is the width t (for example, t = 3 means three elements).
  • Each element is an element of the finite field Fp\mathbb{F}_p.

Round procedure

Repeat the following steps for multiple rounds. The procedure is designed to provide security while limiting computational cost.

  1. AddRoundConstants Add a round-specific constant CiC_i to each element to disrupt input patterns.

    state[i]←state[i]+Ci \text{state}[i] \leftarrow \text{state}[i] + C_i
  2. S-box Apply a fifth-power transformation as the nonlinear S-box (four finite-field multiplications in a straightforward implementation), making inversion of the overall hash difficult.

    state[i]←(state[i])5 \text{state}[i] \leftarrow \bigl(\text{state}[i]\bigr)^5
  3. MDS matrix multiplication Multiply the state by a predetermined MDS (Maximum Distance Separable) matrix to mix its elements.

    state←M×state \text{state} \leftarrow M \times \text{state}

Full and partial rounds

  • Full round
    • Apply the S-box from step 2 to every element.
  • Partial round
    • Apply the S-box to only one element; the remaining elements undergo steps 1 and 3.

This reduces computational cost, particularly the number of multiplications in a ZK circuit.

Parameter selection

Designers precompute and publish the following parameters.

  • Number of rounds (the combination of full and partial rounds)
  • Round constants
  • MDS matrix

These parameters are optimized to minimize the constraints required by zero-knowledge proofs while targeting a security level of 128 bits. Using the published parameters for the selected configuration enables secure and efficient implementation of Poseidon.

Poseidon example

The following numerical example uses width t = 3 and prime p = 17, a very small finite field, to illustrate one full round followed by one partial round. Real Poseidon configurations use much larger primes and constants (the original example describes primes in the 64-bit to 256-bit range), but the general procedure is the same.

Assumptions

Symbol Value Description
Initial state [5,8,10][5, 8, 10] Generated from the absorbed input data
MDS matrix [211121112]\begin{bmatrix} 2 & 1 & 1 \\ 1 & 2 & 1 \\ 1 & 1 & 2 \end{bmatrix} A 3 × 3 matrix that mixes the elements
First round [3,7,2][3, 7, 2] Used by AddRoundConstants
Second round [5,11,13][5, 11, 13] Used by AddRoundConstants

First round (full round)

Step State after each step
Initial state [5,8,10][5, 8, 10]
AddRoundConstantsstate[i]+=Ci(mod17)\text{state}[i] += C_i \pmod{17} [8,15,12][8, 15, 12]
S-box (all elements)state[i]=state[i]5(mod17)\text{state}[i] = \text{state}[i]^5 \pmod{17} [9,2,3][9, 2, 3]
MDS matrix multiplicationM×state(mod17)M \times \text{state} \pmod{17} [6,16,0][6, 16, 0]

Second round (partial round)

Step State
End of previous round [6,16,0][6, 16, 0]
AddRoundConstants [11,10,13][11, 10, 13]
S-box (first element only) [10,10,13][10, 10, 13]
MDS matrix multiplication [9,9,12][9, 9, 12]

In ZK applications, proof-generation cost and time can become bottlenecks, making hash functions such as Poseidon, designed to require very few circuit constraints, particularly valuable.

Together, these techniques support confidential and verifiable operations.

Architecture

Balance & Amount

Encrypted balances and transaction amounts

With ordinary ERC20 tokens, anyone can inspect an account's balance. Encrypted ERC stores balances and confidential transaction amounts in encrypted form, so their plaintext values are not visible.

Balance management

The following struct manages account balances and transaction histories.

solidity
struct EncryptedBalance {
    EGCT eGCT;  // Encrypted balance
    mapping(uint256 index => BalanceHistory history) balanceList;  // Historical balance records
    uint256 nonce;  // Balance version management
    uint256 transactionIndex;  // Transaction index
    uint256[7] balancePCT;  // Latest balance encrypted using Poseidon-based encryption
    AmountPCT[] amountPCTs;  // Encrypted receipts for individual transactions
}

struct BalanceHistory {
    uint256 index;
    bool isValid;
}
  • eGCT
    • ElGamal Ciphertext。
    • The user's current balance encrypted using ElGamal.
    • Arithmetic can be performed without decrypting it.
  • balanceList
    • For each transaction, a balance history entry is maintained using a hash of the encrypted balance (eGCT) and nonce.
    • This enables verification of previously recorded balance states.
  • nonce
    • A version identifier for the current balance.
    • Incremented during balance-changing operations as described by the balance update logic, preventing reuse of a balance version.
    • Because nonce is part of the key used to generate balanceList entries, changing the nonce invalidates lookups based on earlier versions.
  • transactionIndex
    • An index identifying transactions associated with the user, such as deposits, transfers, or withdrawals.
    • The same index is not reused.
  • balancePCT
    • Poseidon Ciphertext Balance。
    • Encrypted information representing the current total balance.
    • Stored as an array to organize the constituent values.
    • Zero-knowledge proofs can establish consistency with the amountPCTs history.
  • amountPCTs
    • Poseidon Ciphertext Amounts。
    • Encrypted transaction details associated with operations such as deposits, transfers, and withdrawals.
    • Stored as an array because multiple transactions may exist; the records support subsequent history verification.
  • BalanceHistory
    • index
      • The same value as transactionIndex.
    • isValid
      • Indicates whether the balance snapshot is valid.
      • Under normal circumstances, an invalid value is not recorded.

Balance update flow

The following operations are performed when a user's balance changes.

  1. Calculate the new encrypted balance (eGCT) using ElGamal.
  2. Generate and append an AmountPCT containing encrypted details of the new transaction.
  3. Update balancePCT, which represents encrypted total-balance information.
  4. Generate a hash combining eGCT and nonce.
  5. Use the hash as a key in balanceList to record transactionIndex and the transaction state.
  6. Increment transactionIndex.

Key registration

Before using encrypted tokens, users must register information associated with their encryption key. This requires a separate public-private key pair rather than the private key of the user's EOA. The BabyJubJub curve used by Encrypted ERC differs from secp256k1, which Ethereum accounts use.

  • Proving key validity in advance Establishes that the user's public key was correctly generated before executing transactions.
  • Preventing cross-chain impersonation Preregister a hash combining the chain ID, private key, and address to prevent reuse of proofs for other chains or addresses.
  • Optimizing on-chain costs Registering the key once rather than repeatedly verifying its registration proof for each transaction reduces gas costs.

The encryption private key is derived from a signature made by the user's EOA and stored on the user's device. This design is intended to keep the encryption private key inaccessible to other parties. If the encryption private key is lost, signing the same message can recover it provided the derivation produces the same signature.

Registration data

go
type RegistrationCircuit struct {
    Sender RegistrationSender
}

The registration operation receives information associated with the sender and verifies the public key and registration hash. It checks that the public key is a point on the BabyJubJub elliptic curve and fails for invalid values.

What does it mean for a point to be on an elliptic curve?

In elliptic-curve cryptography, a public key is represented by a point (x, y) on the curve. The curve-membership check determines whether the point satisfies the curve equation. A point outside the curve is invalid. Additional checks required by the cryptographic scheme may also apply.

The proof checks the Poseidon hash of chainId || privateKey || address against the supplied value.

Registration flow

  1. The user generates a zero-knowledge proof for RegistrationCircuit.
    • Public key
    • Zero-knowledge proof generated using the private key
    • Registration hash
      • A hash generated by Poseidon(chainID, secretKey, userAddress)
  2. Submit the proof to the Registrar contract.
  3. The Registrar contract uses the RegistrationCircuit verifier to check the following.
    • Whether the public key lies on the BabyJubJub curve
    • Whether the public key corresponds to the private key
    • Whether the registration hash was calculated correctly (chain ID, private key, and address)
  4. If verification succeeds, the Registrar contract stores the following on-chain.
    • The user's public key
    • Registration hash
  5. For transactions such as deposits, transfers, and withdrawals, perform the following checks.
    • Query the Registrar contract for the transaction account's registration information.
    • Permit the operation if the account is registered.

Role of the Registrar contract

  • Registration information repository Stores public keys and registration hashes so that an account's previously verified registration can be checked on-chain.
  • Authorization hub The Encrypted ERC contract queries the Registrar to check whether the relevant address is registered before executing operations such as deposits, transfers, or withdrawals.

Deposit Operation

In Encrypted ERC's Converter mode, ERC20 tokens can be converted into encrypted tokens.

Token Tracker

Converter mode introduces a mechanism called the Token Tracker to handle multiple different ERC20 tokens. Tracked tokens are assigned unique sequential tokenId values beginning at 1. When a user deposits an unregistered token for the first time, the protocol registers the token automatically and assigns it a new tokenId. This allows different tokens to be managed within a common system.

No zero-knowledge proof required

Unlike Mint, Transfer, Withdraw, and Register, the Deposit operation does not require a zero-knowledge proof. This is because a deposit converts ordinary ERC20 tokens into a private encrypted representation in one direction. The design has the following properties.

  • The deposited amount is visible on-chain and does not need to be concealed.
  • Deposits are processed using the ERC20 transferFrom function.
  • A zero-knowledge proof is unnecessary for the public deposit amount.

The deposit recipient and amount involved in converting ERC20 tokens to encrypted tokens are public. Subsequent confidential transfers conceal the transferred amount; withdrawals into public ERC20 tokens expose the withdrawn amount as explained below.

Decimal precision adjustment

ERC20 tokens can have different decimal precisions, such as six decimal places for USDC and 18 for WETH. Differences from the decimals used internally by Encrypted ERC require normalization before encryption. The decimal precision is therefore adjusted as follows.

solidity
if (tokenDecimals > decimals) {
    uint256 scalingFactor = 10 ** (tokenDecimals - decimals);
    value = _amount / scalingFactor;
    dust = _amount % scalingFactor;
} else if (tokenDecimals < decimals) {
    uint256 scalingFactor = 10 ** (decimals - tokenDecimals);
    value = _amount * scalingFactor;
    dust = 0;
}

This conversion adjusts amounts expressed in different units to a common internal unit. For example, the following two currencies express their balances in different base units and must be normalized for common accounting.

  • USDC: 1 USDC = 1,000,000 base units (six decimal places)
  • WETH: 1 WETH = 1,000,000,000,000,000,000 base units (18 decimal places)

Encrypted ERC adjusts amounts to account for such differences in units. If a currency with six decimal places is scaled to 18, amounts at finer precision than the original token can become unrepresentable dust when converting back. Encrypted ERC records such remainders so that small residual token amounts caused by precision differences are also accounted for.

When withdrawing encrypted tokens back into ERC20 tokens, the reverse adjustment restores the appropriate underlying token amount.

Technical details of decimals and dust

Assumptions

  • _amount
    • The amount of ERC20 tokens the user wants to deposit (uint256)
  • tokenDecimals
    • Decimal precision of the ERC20 token (for example, six for USDC and 18 for WETH)
  • decimals
    • The common internal precision used by Encrypted ERC (for example, 18)

Processing flow

  • When the ERC20 token has more decimal places than Encrypted ERC Example: tokenDecimals = 20 (20 decimal places) decimals = 18 (Encrypted ERC uses 18 decimal places)

    solidity
    scalingFactor = 10 ^ (20 - 18) = 100;
    value = _amount / 100;
    dust  = _amount % 100;
    • value
      • Amount adjusted to Encrypted ERC precision (integer)
    • dust
      • Remainder after division (dust that cannot be represented at Encrypted ERC precision)

    Because the ERC20 token uses finer units than Encrypted ERC, round down to the supported internal unit and record the remainder as dust.

  • When the ERC20 token has fewer decimal places than Encrypted ERC

    Example: tokenDecimals = 6 (USDC) decimals = 18

    solidity
    scalingFactor = 10 ^ (18 - 6) = 1_000_000_000_000;
    value = _amount * scalingFactor;
    dust = 0;
    • value
      • Amount scaled to Encrypted ERC's 18-decimal precision
    • dust
      • Multiplication is exact, so the remainder is zero.

    Scale the ERC20 token amount to the finer internal units used by Encrypted ERC.

  • When the ERC20 token and Encrypted ERC have the same decimal precision

    No adjustment is needed.

Updating balances

When a user deposits ERC20 tokens, the deposited amount (value) is encrypted using ElGamal with the user's public key. The following balance operations are then performed.

  • For an initial deposit, set eGCT (the encrypted balance) directly.
  • If a balance already exists, combine the values using ElGamal's homomorphic addition, which adds values while they remain encrypted.
  • Generate amountPCT (encrypted transaction data) associated with the transaction and record it in the history.

This amountPCT is used during zero-knowledge proof verification.

solidity
if (balance.eGCT.c1.X == 0 && balance.eGCT.c1.Y == 0) {
    balance.eGCT = _eGCT;
} else {
    balance.eGCT.c1 = BabyJubJub._add(balance.eGCT.c1, _eGCT.c1);
    balance.eGCT.c2 = BabyJubJub._add(balance.eGCT.c2, _eGCT.c2);
}

The following code determines how a new deposit (_eGCT) is added to the user's encrypted balance (eGCT). The operation proceeds as follows.

  • Check whether the user's current encrypted balance is in the initial zero-valued state.
  • If so, set the balance directly to the new deposit (_eGCT).
  • If an encrypted balance already exists, perform homomorphic addition while the values remain encrypted and update the balance.
eGCT

eGCT is a struct representing an ElGamal ciphertext, consisting of two elliptic-curve points (ECPoint) called c1 and c2.

c1.X == 0 && c1.Y == 0 checks whether the ciphertext's c1 is represented by the zero-valued, uninitialized point. If this is true, the balance is uninitialized and _eGCT is stored directly.

_add() performs addition on the BabyJubJub elliptic curve. Both c1 and c2 are updated.

Adding _eGCT to the existing ciphertext updates the encrypted token balance. The ElGamal encrypted-balance construction supports addition of encrypted amounts without decrypting them.

Mint operation

In Encrypted ERC's Standalone mode, encrypted ERC20 tokens are issued (minted).

Private Mint

The Encrypted ERC Mint operation uses zero-knowledge proofs and ElGamal encryption to perform the following.

  • Add newly issued tokens to a user's balance without revealing the issued amount
  • Prevent unauthorized reuse of a mint authorization
  • Store information required by regulators and other authorized auditors

Information stored

Mint uses the following four inputs to the circuit (a set of rules used to verify that the operation was performed correctly).

go
type MintCircuit struct {
    Receiver      Receiver         // Token recipient, including the public key
    Auditor       Auditor          // Regulatory auditor key and encrypted information
    MintNullifier MintNullifier    // Hash establishing mint uniqueness
    ValueToMint   frontend.Variable // Token amount to mint (private)
}
  • Receiver
    • Information for the user receiving encrypted tokens, including ElGamal-encrypted data
  • Auditor
    • Contains information encrypted using the regulatory auditor's public key
  • MintNullifier
    • A unique hash value intended to prevent reuse of a Mint proof (Poseidon hash involving the chain ID and auditor ciphertext)
  • ValueToMint
    • Actual amount of tokens being issued.
    • This amount is handled privately within the zero-knowledge proof.

Circuit validation

The MintCircuit and associated on-chain validation enforce the following checks.

  • Whether the MintNullifier establishing mint uniqueness has already been consumed
  • Whether the Receiver and Auditor ciphertexts were generated correctly
  • Whether the same MintAmount is consistently represented in the Receiver and Auditor ciphertexts

These checks prevent reuse of proofs for duplicate minting and the use of manipulated ciphertexts.

Smart contract processing

After verification of the circuit proof, the Encrypted ERC smart contract performs the following operations.

  1. Use the Receiver public key to construct the ElGamal ciphertext (eGCT) representing the minted tokens
  2. Homomorphically add the newly minted encrypted amount to the current encrypted balance (eGCT)
    • Addition can be performed without revealing the plaintext amounts.
  3. Update balancePCT (current encrypted balance information)
    • Produced using Poseidon-based encryption and used to verify subsequent ZK transactions.

This enables consistent issuance without revealing the amount each recipient receives.

Transfer Operation

Encrypted ERC encrypts transfer amounts and balances, uses zero-knowledge proofs to establish transaction validity, and enables authorized regulators to decrypt the necessary audit information.

Transfer components

Transfers are processed through a cryptographic circuit called TransferCircuit, which includes the following information.

go
type TransferCircuit struct {
	Sender          Sender
	Receiver        Receiver
	Auditor         Auditor
	ValueToTransfer frontend.Variable
}
  • Sender
    • Identifying information for the sender, such as their public key and authorization data
  • Receiver
    • Recipient's public key
  • Auditor
    • Public key used for regulatory auditing
  • ValueToTransfer
    • Amount being transferred (the value to encrypt)

Transfer flow and encryption mechanism

A transfer causes the following state changes.

  • Subtract the transferred amount from the sender's eGCT (encrypted balance).
  • Update the sender's BalancePCT.
  • Add the transferred amount to the recipient's eGCT.
  • Create and store a new AmountPCT for the recipient.
  • Store encrypted information for the auditor.

These operations can be completed without revealing the actual transfer amount or balances.

  1. Verification using a zero-knowledge proof

    Before the transfer, the sender proves the following.

    • The sender is authorized to spend the encrypted tokens, based on knowledge of the private key.
    • The encrypted balance is at least the transfer amount, without disclosing the balance itself.

    This prevents unauthorized spending and transfers that exceed the available balance.

  2. Encrypted transfers using ElGamal

    The transfer amount is represented as follows.

    • Sender
      • Use ElGamal with the sender's public key to represent -X (the negative transfer amount).
    • Recipient
      • Use ElGamal with the recipient's public key to represent +X (the transfer amount).

    The ElGamal construction supports homomorphic addition and subtraction of encrypted amounts, enabling correct balance calculations without revealing the actual balances.

    Example: a balance of 3 minus a transfer of 1 yields 2, which can be verified without revealing these values in the real transaction.

    Anyone can create an ElGamal ciphertext using the recipient's public key. Spending an encrypted balance, however, requires the corresponding authorization and zero-knowledge proof using the private key. Thus, spending and the associated sender-side balance update require the legitimate owner's authorization.

  3. State updates using BalancePCT and AmountPCT

    • BalancePCT
      • Updated encrypted balance information represents the current state.
    • AmountPCT
      • Details associated with the transfer, such as the transfer amount, are recorded using Poseidon-based encryption.

    This enables consistent reconstruction of transfer records for subsequent authorized verification and auditing.

  4. Generate encrypted information for the Auditor

    An auditable transfer record containing the following information is created for regulators or auditors.

    • Transfer amount
    • Sender and recipient identifiers, such as public keys or unique user identifiers
    • Encrypted authorization and transaction metadata, as applicable to the implementation

    The information encrypted under the auditor's public key can subsequently be decrypted by the authorized auditor.

Withdrawal Operation

In Encrypted ERC's Converter mode, users can withdraw encrypted tokens back into ordinary ERC20 tokens. Zero-knowledge proofs enable consistent withdrawals without disclosing the user's remaining encrypted balance.

Information and proofs required for withdrawals

go
type WithdrawCircuit struct {
	Sender      WithdrawSender
	Auditor     Auditor
	ValueToBurn frontend.Variable `gnark:",public"`
}

The withdrawal ZK circuit, WithdrawCircuit, receives the following information.

  • Sender
    • Encrypted balance information and identifier of the user making the withdrawal
  • Auditor
    • Auditor information for tracking the withdrawal
  • ValueToBurn
    • Token amount to withdraw (public information)

The circuit performs the following checks.

  • Whether the user is authorized to spend the encrypted balance (using the key pair)
  • Whether the balance is at least the withdrawal amount
  • Generates encrypted records for the auditor to support regulatory compliance.

Withdrawal processing in the smart contract

After successful proof verification, the smart contract performs the following operations.

  1. Update the encrypted balance

    • Subtract the withdrawal amount from the user's balance using ElGamal homomorphic arithmetic.
    • Update balancePCT to reflect the remaining encrypted balance.
  2. Convert and transfer ERC20 tokens

    After updating the encrypted balance, convert the withdrawn amount back into ordinary ERC20 tokens and send them to the user.

    • Adjust token-specific decimal precision to calculate the appropriate underlying token amount.
    • Send the tokens to the user using the ERC20 transfer function.

Auditor records for regulatory compliance

During withdrawal, information associated with the operation is recorded using the auditor's public key, as described in the original design.

  • Withdrawal amount (public; additional private details associated with the withdrawal may be encrypted)
  • User identifiers, such as public keys or hashes
  • Transaction metadata, such as timestamps and nonces

This allows authorized auditors to inspect encrypted details without making those details publicly readable.

Conclusion

This article covered Avalanche's Encrypted ERC.

I also publish articles on the following platforms.

https://chaldene.net/