bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 13쪽 중 6쪽
should appear in your wallet.
# ERC20 Tokens with Zircuit Canonical Bridge
Zircuit's canonical bridge is derived from the bridge in the OP-stack framework. Therefore, the ERC20 tokens on Zircuit with their counterparts deployed on Ethereum mainnet follow the same architecture. If you would like to deploy an ERC20 token with no special logic, you can do so by using the prepared factory available on address [0x4200000000000000000000000000000000000012](https://explorer.zircuit.com/address/0x4200000000000000000000000000000000000012) on Zircuit.
In some cases, developers may desire to deploy ERC20 contracts with additional functionality that is not available in the templated contract that the factory creates, and they may want for these contracts to work with Zircuit's canonical bridge. This is certainly possible --- you may use any custom implementation provided that it meets the following conditions (you can reference the template implementation show below):
* The token implements the `IOptimismMintableERC20` interface together with EIP165, and reports that this interface is implemented. See function `supportsInterface` in the sample implementation below.
* The canonical bridge is given the privilege to mint tokens to the users when they lock their tokens on L1 by calling the `depositERC20` function on the [L1StandardBridge contract](https://etherscan.io/address/0x386B76D9cA5F5Fb150B6BFB35CF5379B22B26dd8), and to burn tokens from the users' accounts when they call `bridgeERC20` function on the [L2StandardBridge contract](https://explorer.zircuit.com/address/0x4200000000000000000000000000000000000010). See the modifier `onlyBridge`, and functions `mint` and `burn` in the reference implementation.\
\
Note that upon deposit, the bridge on L1 locks the respective amount of tokens and mints them to the user on L2. Upon withdrawal, it burns the respective number of tokens on L2 from the user's balance, and releases them on L1. **The canonical bridge inherently assumes that the number of tokens in circulation on L2 matches the number of tokens locked in the bridge on L1. The developers should not violate this principle.** This might happen by allowing parties other than the bridge to mint and burn tokens, or by implementing features such as rebasing, or fees on transfer.
* The `REMOTE_TOKEN`, `BRIDGE`, and `DECIMALS` storage variables are properly initialized. The `REMOTE_TOKEN` address should match the token deployed on L1 as the bridge performs a check while bridging. The address of the `L2StandardBridge` on Zircuit is [0x4200000000000000000000000000000000000012](https://explorer.zircuit.com/address/0x4200000000000000000000000000000000000012).
Below is a template implementation of an ERC20 that can be further extended with custom logic.
```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface IOptimismMintableERC20 is IERC165 {
function remoteToken() external view returns (address);
function bridge() external returns (address);
function mint(address _to, uint256 _amount) external;
function burn(address _from, uint256 _amount) external;
}
contract MyZircuitERC20 is IOptimismMintableERC20, ERC20 {
/// @notice Address of the corresponding version of this token on the remote chain.
address public immutable REMOTE_TOKEN;
/// @notice Address of the StandardBridge on this network.
address public immutable BRIDGE;
/// @notice Decimals of the token
uint8 private immutable DECIMALS;
/// @notice Emitted whenever tokens are minted for an account.
/// @param account Address of the account tokens are being minted for.
/// @param amount Amount of tokens minted.
event Mint(address indexed account, uint256 amount);
/// @notice Emitted whenever tokens are burned from an account.
/// @param account Address of the account tokens are being burned from.
/// @param amount Amount of tokens burned.
event Burn(address indexed account, uint256 amount);
/// @notice A modifier that only allows the bridge to call
modifier onlyBridge() {
require(msg.sender == BRIDGE, "Only bridge can mint and burn");
_;
}
/// @param _bridge Address of the L2 standard bridge.
/// @param _remoteToken Address of the corresponding L1 token.
/// @param _name ERC20 name.
/// @param _symbol ERC20 symbol.
constructor(
address _bridge,
address _remoteToken,
string memory _name,
string memory _symbol,
uint8 _decimals
)
ERC20(_name, _symbol)
{
REMOTE_TOKEN = _remoteToken;
BRIDGE = _bridge;
DECIMALS = _decimals;
}
/// @notice Allows the StandardBridge on this network to mint tokens.
/// @param _to Address to mint tokens to.
/// @param _amount Amount of tokens to mint.
function mint(
address _to,
uint256 _amount
)
external
virtual
override(IOptimismMintableERC20)
onlyBridge
{
_mint(_to, _amount);
emit Mint(_to, _amount);
}
/// @notice Allows the StandardBridge on this network to burn tokens.
/// @param _from Address to burn tokens from.
/// @param _amount Amount of tokens to burn.
function burn(
address _from,
uint256 _amount
)
external
virtual
override(IOptimismMintableERC20)
onlyBridge
{
_burn(_from, _amount);
emit Burn(_from, _amount);
}
/// @notice ERC165 interface check function.
/// @param _interfaceId Interface ID to check.
/// @return Whether or not the interface is supported by this contract.
function supportsInterface(bytes4 _interfaceId) external pure virtual returns (bool) {
bytes4 iface1 = type(IERC165).interfaceId;
// Interface corresponding to the updated OptimismMintableERC20 (this contract).
bytes4 iface3 = type(IOptimismMintableERC20).interfaceId;
return _interfaceId == iface1 || _interfaceId == iface3;
}
/// @notice Getter for the remote token. Legacy, also use REMOTE_TOKEN
function l1Token() public view returns (address) {
return REMOTE_TOKEN;
}
/// @notice Getter for the bridge. Legacy, also use BRIDGE
function l2Bridge() public view returns (address) {
return BRIDGE;
}
/// @notice Getter for the remote token. Legacy, also use REMOTE_TOKEN
function remoteToken() public view returns (address) {
return REMOTE_TOKEN;
}
/// @notice Getter for the bridge. Legacy, also use BRIDGE.
function bridge() public view returns (address) {
return BRIDGE;
}
/// @dev Returns the number of decimals used to get its user representation.
/// For example, if `decimals` equals `2`, a balance of `505` tokens should
/// be displayed to a user as `5.05` (`505 / 10 ** 2`).
/// NOTE: This information is only used for _display_ purposes: it in
/// no way affects any of the arithmetic of the contract, including
/// {IERC20-balanceOf} and {IERC20-transfer}.
function decimals() public view override returns (uint8) {
return DECIMALS;
}
}
```
# Bridging ZRC to Zircuit
## Easiest Option: Get ZRC on an Exchange, then withdraw to Zircuit
1. **Bybit:** <https://www.bybit.com/en/coin-price/zircuit/>
2. **Bitget:** <https://www.bitget.com/price/zircuit>
3. **Crypto.com:** <https://crypto.com/price/zircuit>
4. **Gate:** <https://www.gate.io/state_compliance_tips>
5. **Hashkey Global:** <https://global.hashkey.com/en-US/spot/ZRC_USDT>
Bridge \~$1 of ETH to Zircuit for transactions & gas fees
* Use Rhino <https://app.rhino.fi/bridge?chain=ARBITRUM&token=ETH&chainOut=ZIRCUIT>
* Or the Native Bridge <https://bridge.zircuit.com/>
## Most Affordable: Use Rhino to bridge ETH, then swap for ZRC
1. Bridge ETH or stablecoins to Zircuit, from a low gas-fee network (e.g. Base or Solana) using Rhino
* <https://app.rhino.fi/bridge?chain=BASE&token=ETH&chainOut=ZIRCUIT>
* If you're bridging stables, don't forget to bridge a bit of ETH for gas by selecting *"Get $1 ETH on Zircuit for transactions"*
2. Swap ETH or stables for ZRC using a DEX
* Zuit: <https://zuit.xyz/swap>
* Ocelex: <https://app.ocelex.fi/swap>
* Dodo: <https://app.dodoex.io/swap/network/zircuit-mainnet>
## On Ethereum: Get ZRC on Uniswap, then Bridge to Zircuit
* Get ZRC on Uniswap on Ethereum
* <https://app.uniswap.org/explore/tokens/ethereum/0xfd418e42783382e86ae91e445406600ba144d162>
* Bridge ZRC to Zircuit using the Native Bridge:
* <https://bridge.zircuit.com/>
* Bridge \~$1 of ETH to Zircuit for transactions & gas fees
* Use Rhino <https://app.rhino.fi/bridge?chain=ARBITRUM&token=ETH&chainOut=ZIRCUIT>
* Or the Native Bridge <https://bridge.zircuit.com/>
# Bridged Token Addresses
Ethereum ERC-20 tokens that have corresponding bridged representations on the Zircuit Mainnet can be found on the Zircuit Block Explorer [website](https://explorer.zircuit.com/tokens).
A JSON list of the token mappings is also [available](https://bridge.zircuit.com/api/tokens).
# Escape Hatch
{% hint style="info" %}
This page is necessary for the Sepolia-based Zircuit Legacy Testnet, which was deprecated in June 2025. Escape hatch functionality is available on the mainnet though it is only usable if the chain if offline for a sufficiently long period of time.
{% endhint %}
## Overview
This page describes the necessary steps to withdraw funds from the Zircuit network in the event blocks cease to be produced for a long period of time. These steps bypass the conventional withdrawal mechanisms of Zircuit and allow for a forced withdrawal of assets.
These steps utilise functionally called an *escape hatch*, which allows users to remove Ether and tokens from a Zircuit network in case a state update has not occurred in the past 30 days. Assets that are withdrawn this way are said to be *escaped***.** For the purpose of this page, the L2 (layer 2) network is the Zircuit Legacy Testnet and the L1 (layer 1) is Sepolia.
{% hint style="info" %}
For the intentionally deprecated Legacy Testnet, the delay required to use this functionality is intentionally set to 5 days.
{% endhint %}
## Eligible Assets for Escape
The Zircuit Legacy Testnet escape hatch allows the withdrawal of Legacy Testnet ETH and WETH from `OptimismPortal`, and any ERC20 tokens that were bridged using Zircuit `L1StandardBridge` on Sepolia. These funds account for the majority of assets present on the Legacy Testnet.
Throughout this page, several assumptions are made in order to simplify the instructions to withdraw the assets described above. Future versions of this functionality will support additional assets; be sure to use the instructions for the right escape hatch.
## Escape Hatch Tooling
Scripts that implement the functionality necessary to escape ETH and ERC20 tokens can be found [here](https://github.com/zircuit-labs/zircuit-escape-hatch-tooling), which implement the functionality described below. Users who are not interested in understanding how the escape hatch works can simply use the scripts.
## Escaping with EOAs
These instructions can be used once the escape hatch functionality is enabled, due to a lack of state root update.
### Escaping ETH
Users can initiate ETH withdrawals via the `escapeETH()` function on the `OptimismPortalProxy` contract. This process requires generating and verifying inclusion proofs to reconstruct the user's balance on L2 at the last known valid state.
```solidity
/// @notice Function to withdraw ETH that user had on L2 if more than 30 days passed since output root was
/// published.
/// @param _outputRootProof Inclusion proof of the L2ToL1MessagePasser contract's storage root.
/// @param _accountState State of user account on L2.
/// @param _proof Proof of account state on L2.
function escapeETH(
Types.OutputRootProof calldata _outputRootProof,
Types.AccountState calldata _accountState,
bytes[] calldata _proof
)
external
```
Here is a TypeScript/ethers.js example showing how to prepare and submit an `escapeETH()` transaction.
```typescript
import * as ethers from "ethers";
import L2OutputOracle from "./L2OutputOracle.json";
import OptimismPortal from "./OptimismPortal.json";
const accountForEscapeAddress = "<EOA ADDRESS>"
const l1Provider = new ethers.providers.JsonRpcProvider("<L1 PROVIDER>")
const l2Provider = new ethers.providers.JsonRpcProvider("<L2 PROVIDER>")
const l2tol1MessagePasserAddress = "0x4200000000000000000000000000000000000016"
const L2OutputOracleAddress = "<L2OuputOracle ADDRESS>"
const OptimismPortalAddress = "<OptimismPortal ADDRESS>"
const L2OutputOracleContract = new ethers.Contract(L2OutputOracleAddress, L2OutputOracle.abi, l1Provider);
const OptimismPortalContract = new ethers.Contract(OptimismPortalAddress, OptimismPortal.abi, l1Provider);
// Fetch the most recent output root published
const latestOutputIndex = await L2OutputOracleContract.latestOutputIndex();
const latestOutput = await L2OutputOracleContract.getL2Output(latestOutputIndex);
let l2OutputBlockNumber = latestOutput.l2BlockNumber
// Obtain the arguments required to verify the state root of the L2 agains the output root that was published in the L2OutputOracle
const l2Block = await l2Provider.send('eth_getBlockByNumber', [l2OutputBlockNumber.toHexString(), false]);
let messagePasserStorageRoot = (await l2Provider.send('eth_getProof', [
l2tol1MessagePasserAddress,
[],
l2OutputBlockNumber.toHexString()
])).storageHash
let outputRoot = ethers.utils.keccak256(ethers.utils.defaultAbiCoder.encode([ "uint", "uint","uint","uint"],["0x0",l2Block.stateRoot,messagePasserStorageRoot,l2Block.hash]))
if (outputRoot !== latestOutput.outputRoot) {
throw new Error("Roots do not match!")
}
// Obtain the merkle proof of the account state that we are trying to escape
let accountProof = await l2Provider.send('eth_getProof', [
accountForEscapeAddress,
[],
l2OutputBlockNumber.toHexString()
])
let escapeTx = await OptimismPortalContract.populateTransaction.escapeETH(
{
version: ethers.constants.HashZero,
stateRoot: l2Block.stateRoot,
messagePasserStorageRoot: messagePasserStorageRoot,
latestBlockhash: l2Block.hash
},
{
nonce: accountProof.nonce,
balance: accountProof.balance,
storageRoot: accountProof.storageHash,
codeHash: accountProof.keccakCodeHash,
},
accountProof.accountProof
)
```
### Escaping ERC20s
Unlike ETH, which is tracked via account balances, ERC20 token balances are stored in smart contract storage slots. Escaping ERC20s therefore requires not only proving the state of the ERC20 contract itself, but also providing a Merkle proof of the user’s token balance stored in the contract's storage trie.
The escape mechanism for ERC20s is available via the `escapeERC20()` function on the **`L1StandardBridgeProxy`** contract on Ethereum.
```solidity
/// @notice Allows users to escape ERC20 tokens if no output root has been published for over 30 days.
/// @param _localToken Address of the token on L1.
/// @param _remoteToken Addres of the corresponding token on L2.
/// @param _outputRootProof Inclusion proof of the L2ToL1MessagePasser contract's storage root.
/// @param _accountState State of the ERC20 token contract on L2.
/// @param _stateProof Proof of the ERC20 contract state.
/// @param _tokenBalance Balance the user had of the ERC20 on L2.
/// @param _storageProof Proof of value on the storage slot with the user balance.
function escapeERC20(
address _localToken,
address _remoteToken,
Types.OutputRootProof calldata _outputRootProof,
Types.AccountState calldata _accountState,
bytes[] calldata _stateProof,
uint256 _tokenBalance,
bytes[] calldata _storageProof
)
```
Here’s a TypeScript/ethers.js script that shows how to gather the necessary proofs and invoke the `escapeERC20()` function.
```typescript
import * as ethers from "ethers";
import L2OutputOracle from "./L2OutputOracle.json";
import L1StandardBridge from "./L1StandardBridge.json";
const accountForEscapeAddress = "<EOA ADDRESS>"
const l2ERC20ForEscape = "<ADDRESS OF ERC20 ON L2>"
const l1ERC20ForEscape = "<ADDRESS OF ERC20 ON L1>"
const l1Provider = new ethers.providers.JsonRpcProvider("<L1 PROVIDER>")
const l2Provider = new ethers.providers.JsonRpcProvider("<L2 PROVIDER>")
const l2tol1MessagePasserAddress = "0x4200000000000000000000000000000000000016"
const L2OutputOracleAddress = "<L2OuputOracle ADDRESS>"
const L1StandardBridgeAddress = "<L1StandarBridge ADDRESS>"
const L2OutputOracleContract = new ethers.Contract(L2OutputOracleAddress, L2OutputOracle.abi, l1Provider);
const L1StandardBridgeContract = new ethers.Contract(L1StandardBridgeAddress, L1StandardBridge.abi, l1Provider);
// Fetch the most recent output root published
const latestOutputIndex = await L2OutputOracleContract.latestOutputIndex();
const latestOutput = await L2OutputOracleContract.getL2Output(latestOutputIndex);
let l2OutputBlockNumber = latestOutput.l2BlockNumber
// Obtain the arguments required to verify the state root of the L2 agains the output root that was published in the L2OutputOracle
const l2Block = await l2Provider.send('eth_getBlockByNumber', [l2OutputBlockNumber.toHexString(), false]);
let messagePasserStorageRoot = (await l2Provider.send('eth_getProof', [
l2tol1MessagePasserAddress,
[],
l2OutputBlockNumber.toHexString()
])).storageHash
let outputRoot = ethers.utils.keccak256(ethers.utils.defaultAbiCoder.encode([ "uint", "uint","uint","uint"],["0x0",l2Block.stateRoot,messagePasserStorageRoot,l2Block.hash]))
if (outputRoot !== latestOutput.outputRoot) {
throw new Error("Roots do not match!")
}
// Determine the storage slot were the user balance was stored in the L2 ERC20
const UserERC20BalanceStorageSlot = ethers.utils.keccak256(ethers.utils.defaultAbiCoder.encode(["uint","uint"],[accountForEscapeAddress,0]))
// Get merkle proof of the ERC20 L2 account state and merkle proof of user balance
let ERC20AccountProof = await l2Provider.send('eth_getProof', [
l2ERC20ForEscape,
[UserERC20BalanceStorageSlot],
l2OutputBlockNumber.toHexString()
])
let escapeTx = await L1StandardBridgeContract.populateTransaction.escapeERC20(
l1ERC20ForEscape,
l2ERC20ForEscape,
{
version: ethers.constants.HashZero,
stateRoot: l2Block.stateRoot,
messagePasserStorageRoot: messagePasserStorageRoot,
latestBlockhash: l2Block.hash
},
{
nonce: ERC20AccountProof.nonce,
balance: ERC20AccountProof.balance,
storageRoot: ERC20AccountProof.storageHash,
codeHash: ERC20AccountProof.keccakCodeHash,
},
ERC20AccountProof.accountProof,
ERC20AccountProof.storageProof[0].value,
ERC20AccountProof.storageProof[0].proof
)
```
In this example, it is assumed that ERC20 balances are stored in a `mapping` at slot `0` as this is the slot of the default mintable ERC20 used by the `StandardBridge`.
## Escaping Assets Held in Smart Contracts
When users deposit assets into smart contracts on L2 (e.g., staking pools or token vaults), those assets are often pooled. This makes escape more complex than with EOAs, since:
* The contract may hold tokens on behalf of many users.
* Each user's entitlement must be calculated from contract state, not just simple balances.
To solve this, Zircuit introduces *resolver contracts* on L1, which encapsulate the logic needed to read the L2 contract’s storage and compute how much a user can rightfully claim. Resolver contracts are explained in this [paper](https://arxiv.org/abs/2503.23986).
{% hint style="info" %}
Resolver contracts are not supported for the Legacy Testnet escape hatch.
{% endhint %}
## Further Reading
Additional details can be found in the [paper](https://arxiv.org/abs/2503.23986) describing the escape hatch mechanism.
# Simulation
Enables developers to test, debug, and analyze transactions before executing them on the live network
### Overview
Transaction simulation allows you to preview the exact outcomes of your transactions without actually submitting them to the blockchain. This is invaluable for:
* **Pre-execution Testing**: Verify transaction success and gas usage before committing
* **Smart Contract Debugging**: Identify potential issues in contract interactions
* **State Change Analysis**: Understand how transactions 프로젝트로 돌아가기