Skip to main content

Overview

FHERC20 Wrappers enable you to convert standard ERC20 tokens or native tokens (e.g., ETH) into confidential FHERC20 tokens and vice versa. This creates a privacy layer on top of existing tokens, allowing users to transact privately while maintaining interoperability with the broader DeFi ecosystem.

Privacy Layer

Transform transparent ERC20 or native token balances into encrypted FHERC20 balances for confidential transactions.

Reversible

Unshield confidential tokens back to standard ERC20 or native tokens at any time through a secure claim process.

1:1 Backing

Each shielded token is backed by the underlying token held in the wrapper contract, with a rate-based conversion for decimal normalization.

DeFi Bridge

Bridge between transparent DeFi protocols and confidential trading/transfers.

Wrapper Types

FHERC20 provides two wrapper contracts: Both wrappers share the same unshielding flow via the FHERC20WrapperClaimHelper.

Rate and Decimal Conversion

Wrappers normalize token decimals to fit within the euint64 type. The maximum confidential decimals default to 6 (configurable via _maxDecimals()).
For an ERC20 with 18 decimals:
  • rate() = 10^(18 - 6) = 10^12
  • Shielding 1,000,000,000,000 (1e12) underlying tokens produces 1 confidential token
  • Amounts are truncated to the nearest multiple of rate() during shielding
Some non-standard tokens such as fee-on-transfer or other deflationary-type tokens are not supported by the wrapper.

ERC20 Wrapper (FHERC20ERC20Wrapper)

How It Works

1

Shield Tokens

User deposits standard ERC20 tokens into the wrapper contract, which mints an equivalent amount of confidential FHERC20 tokens (divided by the rate).
2

Confidential Transfers

User can now transfer the shielded tokens confidentially using all FHERC20 features while balances remain encrypted.
3

Unshield Request

When ready to exit, user burns confidential tokens. The burned amount is marked as publicly decryptable via FHE.allowPublic, and a claim is created.
4

Decrypt Off-Chain

The user (or anyone) requests decryption of the burned amount off-chain via decryptForTx, receiving the plaintext and a decryption proof.
5

Claim Tokens

The user submits the plaintext and proof on-chain via claimUnshielded. The contract verifies the proof and transfers the underlying ERC20 tokens (multiplied by the rate).

Shielding Tokens

Parameters:
  • to: Address to receive the shielded (confidential) tokens
  • amount: Amount of ERC20 tokens to shield (will be truncated to nearest multiple of rate())
Returns: The encrypted amount of confidential tokens minted.

ERC1363 Direct Shielding

The ERC20 wrapper also implements the ERC1363 onTransferReceived callback, allowing users to shield tokens in a single transaction without a separate approval step:

Native Wrapper (FHERC20NativeWrapper)

The native wrapper shields native tokens (e.g., ETH) or WETH into confidential FHERC20 tokens.

Shield Native Tokens

Parameters:
  • to: Address to receive the shielded tokens
  • value: Amount of WETH to shield (for shieldWrappedNative)
  • msg.value: Amount of native currency to shield (for shieldNative)
Amounts are truncated to the nearest multiple of rate(). Any dust below the threshold is refunded to the caller.

Unshielding Tokens

Unshielding is a three-step process shared by both wrapper types: burn on-chain, decrypt off-chain, then claim with proof.

Step 1: Unshield (Burn and Create Claim)

Parameters:
  • from: Address whose confidential tokens to burn (caller must be from or an operator for from)
  • to: Address to receive the underlying tokens after claiming
  • amount: Amount of confidential tokens to unshield
This function:
  1. Burns the specified amount of confidential tokens from from
  2. Calls FHE.allowPublic(burned) so anyone can request decryption of the burned amount
  3. Creates a claim for the recipient
Due to the zero-replacement behavior, if you attempt to unshield more than your balance, zero tokens will be burned and you’ll have a claim for zero tokens.

Step 2: Decrypt Off-Chain

Retrieve the claim’s ctHash using getUserClaims, then request decryption via decryptForTx. Since FHE.allowPublic was called, no permit is needed:

Step 3: Claim Unshielded Tokens

Submit the plaintext and proof to the contract. The contract verifies the proof via FHE.verifyDecryptResult and transfers the underlying tokens (multiplied by the rate):
Parameters:
  • unshieldRequestId: The ciphertext hash identifying the claim
  • unshieldAmountCleartext: The plaintext value returned by decryptForTx
  • decryptionProof: The proof proving the plaintext is authentic

Batch Claiming

You can claim multiple unshield requests in a single transaction:

Claim Management

Claim Structure

Getting Claim Information

Getting User Claims

Returns all pending (unclaimed) claims for a user:

Events


Complete Examples

ERC20 Wrapper

Native Wrapper


Security Considerations

Token Compatibility

FHERC20ERC20Wrapper only works with standard ERC20 tokens. It will NOT work with:
  • Rebasing tokens (token balance changes automatically)
  • Fee-on-transfer tokens (tokens that charge fees)
  • Already-encrypted FHERC20 tokens
Always test with the specific token before deploying to production.

Claim Flow

Claiming requires completing the off-chain decryption step first:
Implement proper UI feedback for the decryption step.

Zero-Replacement

If you unshield more than your balance, you get zero:
Always ensure sufficient balance before unshielding.

Rate Conversion

Be aware of the rate conversion when shielding and unshielding:

Claim Management

Users can accumulate multiple pending claims. Use batch claiming for efficiency:
Provide UI to track and manage multiple claims.

Use Cases

DEX Privacy

Shield tokens before trading on a confidential DEX, then unshield profits. Your trading activity and positions remain private.

Private Payments

Shield stablecoins for confidential payments, then unshield to cash out to bank accounts or fiat on-ramps.

Confidential Payroll

Companies can shield tokens, distribute salaries confidentially, and employees unshield to receive standard tokens.

Privacy Pools

Create pools where users deposit tokens for privacy, transact confidentially, and withdraw when desired.