AvaCloud API
AvaCloud App
Encrypted ERC
Encrypted ERC
  • Welcome
  • 🚀GETTING STARTED
    • What is Encrypted ERC ?
    • Protocol Overview
  • 🏘️ARCHITECTURE
    • Balance & Amount
    • Deposit Operation
    • Transfer Operation
    • Withdrawal Operation
  • ⚙️USAGE
    • SDK Overview
    • useEERC
    • useEncryptedBalance
Powered by GitBook

© 2025 Ava Labs, Inc.

  1. ARCHITECTURE

Withdrawal Operation

When a user wants to withdraw their tokens from the encrypted system, they initiate a withdrawal process that involves both their encrypted balance and regular ERC20 tokens. The process starts with the user's encrypted balance, which is stored in the smart contract. When initiating a withdrawal, the user must first prove they have sufficient funds through a withdrawal circuit.

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

The circuit takes three key pieces of information: the sender's details (including their encrypted balance), the auditor's information, and the amount they want to withdraw (ValueToBurn). This amount is marked as public since it will eventually be visible on-chain when converted to regular ERC20 tokens.

Before processing the withdrawal, the system performs several validations through the circuit. It verifies the user's identity using their public-private key pair and confirms their encrypted balance is sufficient for the withdrawal. The circuit also creates an encrypted record for the auditor, ensuring regulatory compliance without compromising privacy.

The smart contract then handles the actual withdrawal process. It first updates the user's encrypted balance by subtracting the withdrawal amount. This operation happens in encrypted space using ElGamal encryption. The contract also updates the user's balancePCT, which represents their current balance state after the withdrawal.

Finally, the contract handles the conversion from encrypted to regular ERC20 tokens. This step includes managing any necessary decimal adjustments between the two token systems, as different tokens might have different decimal places. The contract calculates the correct amount and transfers the regular ERC20 tokens to the user's address.

PreviousTransfer OperationNextSDK Overview

Last updated 5 months ago

Was this helpful?

🏘️