Depositing Funds to Cloak
Introduction
Most Cloak instances are deployed as L3 chains on top of Scroll. That means that there is a canonical smart contract token bridge between Scroll and Cloak.
The general deposit process for Cloak chain operators is:
- Bridge assets to Scroll via the canonical bridge (from Ethereum) or via 3rd-party bridges.
- Deposit to Cloak via the Cloak bridge.
The remainder of this document will focus on Step 2.
Integration options
For bridging your users' assets to Cloak, you can implement the above process in your frontend. Alternatively, you can also implement your own liquidity bridge by bridging a certain amount of tokens to Cloak, and distributing them to users based on your application logic.
Overview of the Cloak Bridge
The Cloak bridge implements a general message-passing interface between L2 (Scroll) and L3 (Cloak). Most of the bridge code is inherited from the Scroll bridge.
- The user calls one of the token gateway contracts to initiate the deposit:
HostERC20Gateway.depositERC20
orHostETHGateway.depositETH
. - The token gateway relays the message to
HostMessenger
, which enqueues a message onHostMessageQueue
. - The L3 sequencer node picks up the message and relays it to Cloak via
ValidiumERC20Gateway
.
Most of the above contracts are implementation details; users generally mainly interact with the gateway contracts.
A Note on Stealth Deposits
Unlike the Scroll bridge, the Cloak bridge uses stealth deposits, meaning that the deposit target address is encrypted. This is necessary, so that the L3 confidential identity is not exposed publicly on L2. We also want to avoid easily linking L2 and L3 accounts.
Prerequisites
We recommend using the @scroll-tech/cloak-js
package.
This package provides the Cloak network configurations, and tools for encrypting and tracking deposits.
It supports viem
and ethers-js
.
To use this package in your JavaScript or TypeScript project, simply install and then import it:
import { abis, cloak } from '@scroll-tech/cloak-js';
const c = cloak('local-devnet');
console.log(c.contracts());
Depositing ETH to Cloak
See the full example at deposit-eth.ts example in the @scroll-tech/cloak-js
package.
The deposit process is as follows.
-
Fetch the current encryption key.
-
Encrypt the target address using the encryption key.
- It is recommended to generate a unique L3 address for the user. One that is not used on another networks.
-
Send the deposit to the L2 bridge.
-
Set up deposit tracking.
-
Wait for the deposit to be confirmed on L3.
Depositing ERC20 Tokens to Cloak
See the full example at deposit-erc20.ts example in the @scroll-tech/cloak-js
package.
ERC20 deposits are similar to ETH deposits, but they happen through the ERC20Gateway
and require a token approval transaction on L2.
-
Fetch the current encryption key.
-
Encrypt the target address using the encryption key.
-
Approve the Cloak bridge to spend your ERC20 token.
-
Send the deposit to the L2 bridge.
-
Set up deposit tracking.
-
Wait for the deposit to be confirmed on L3.
ERC20 Token Mapping
The Scroll-Cloak bridge can permissionlessly bridge any valid ERC20 token. The bridge will deterministically compute the corresponding L3 token address, which will not change after the first deposit. L2 ETH is bridged into L3 Wrapped ETH.
ETH deposits
By default, L2 ETH is deposited into L3 Wrapped ETH (ERC20 token), not into the L3 gas token. L3 gas is free, so users do not need to hold any gas token.
The L2-L3 token mapping can be queried via the HostERC20Gateway
contract on L2: