LogoLogo
  • Introduction
  • Motivation
  • Roadmap
  • FAQ
  • Technical Walkthrough
  • Using Redact
    • Confidential Balances (Wallet)
    • Encrypting
    • Decrypting
    • Confidential Transfer (Sending)
  • Architecture
    • FHERC20 Token Standard
    • FHERC20.sol
    • ConfidentialERC20.sol
      • RedactCore.sol
    • CoFHE Overview
Powered by GitBook
On this page
  • 1. Add a new token
  • 2. Approval
  • 3. Encryption
  1. Using Redact

Encrypting

PreviousConfidential Balances (Wallet)NextDecrypting

Last updated 15 days ago

Encrypting is the process of converting your ERC20 balance into a confidential and private FHERC20 balance. The full process for encryption involves 3 steps:

  1. Add a new token (optional)

  2. Approval (skipped if ERC20 allowance is sufficient)

  3. Encrypt

1. Add a new token

In addition to the pre-deploy tokens, the system allows you to add a custom token by clicking the "Add Token" button. This option is available in both the main tokens section and the portfolio section. To add a token, the user must first provide the contract address of the public ERC20 token. The system will then search for it.

If the confidential token has already been deployed, the user simply needs to click "Add," and the confidential version of the token will be added to the token list. If the confidential token has not been deployed, the user must also click "Add." In this case, only the public version of the token will be added to the list, and the first time the user encrypts the token, the contract for the confidential version will be deployed. Once deployed, the eToken will automatically be included in the token list.

image placeholder

FHERC20 Deployment

The FHERC20 contract (FHERC20 Token Standard) is responsible for holding your encrypted balances, and performing encrypted transfers. More specifically, the ConfidentialERC20 contract (ConfidentialERC20.sol) is built on the FHERC20 core, and inherits the encrypted functionality. Therefore, in order to encrypt your ERC20 balance, we must first deploy a "paired" ConfidentialERC20 which points at the underlying ERC20 we wish to encrypt.

Each ConfidentialERC20 (and paired ERC20) only needs to be deployed once. Once it is deployed, all future wrapping and unwrapping will use this contract for all users.

In Redact, deploying a new ConfidentialERC20 is simple, and only requires a single transaction. This is what the Deployment flow looks like in the Redact UI:

2. Approval

In order to encrypt (or wrap) your ERC20 tokens, they must first approve them for use in the ConfidentialERC20 smart contract. Only the amount to wrap must be approved.

In the Redact UI, this is step 2 of the wrapping process, and appears like so:

3. Encryption

Now that the ConfidentialERC20 has been deployed, and the amount to encrypt has been approved for spend, we can encrypt our ERC20 balance to make it confidential.

function encrypt(address to, uint128 value) public {
  if (to == address(0)) to = msg.sender;
  _erc20.safeTransferFrom(msg.sender, address(this), value);
  _mint(to, value);
  emit EncryptedERC20(msg.sender, to, value);
}

This function withdraws the ERC20 token from the sender's wallet, and in turn performs an encrypted _mint operation which uses FHE.add to increase the sender's encrypted balance of the ConfidentialERC20.

In the Redact UI, the wrapping processes appears like this:

After the Encryption transaction succeeds, we can see that in the wallet the encrypted balance has been updated. Each account's balance is only visible to that account and this balance will be seen as encrypted to all other accounts.

Lets quickly take a look at this transaction in a block explorer:

This shows that some unknown amount of eLINK has been minted (aka transferred from the zero address), but it is not revealed how much has been minted.

Note that in this situation we can infer the amount minted from the public LINK transferred, but that is not true for confidential transfers: Confidential Transfer (Sending)

TX:

Tx:

shows the internal logic that handles encrypting of balances:

TX:

Notice that in the transaction screenshot above that the amount of LINK transferred is public (1 LINK), but the amount of eLINK transferred is private and is shown as an indicated amount (0.0001 eLINK). Read more about indicated balances here:

https://sepolia.etherscan.io/tx/0x21a...b7d
https://sepolia.etherscas.io/tx/0x777...d0b
ConfidentialERC20.sol#L80-L85
https://sepolia.etherscan.io/tx/0xb03...22f
Deployment flow diagram. (1) Initial, (2) Pending, (3) Success
Approval flow diagram. (1) Initial, (2) Pending, (3) Success
Encryption flow Diagram. (1) Initial, (2) Pending, (3) Success
Example "Encrypt" transaction in Etherscan
Indicated Balances