ZetaChain 백서

ZetaChain

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 5쪽 중 3쪽

rs need access to a full node, which is much cheaper and makes scaling to multiple external chains and more validator nodes much easier. The disadvantage of passive mode is that the liveness of external chain inbound observation is dependent on the sequencer, and also subject to censorship by the sequencer. This is the same situation as the optimistic rollup where the liveness of the rollup is dependent on a sequencer. To mitigate this, everyone is able to be a sequencer if they so choose, and a sequencer can be incentivized by the creation of a competitive market. In particular, dApps have a vested interest in running a sequencer. Another advantage of running passive observation mode with a sequencer is that the dApps are in control of the observation ordering. For efficiency reasons, the active mode does not enforce observation ordering, but if the observation ordering is important to a dApp, it can opt to run its own sequencer in synchronous observation mode (i. e. wait for each observation to be finalized by ZetaChain before moving on to the next). 4.3. Multi-party Threshold Signature Scheme ZetaChain needs to hold an account on external chains in order to custody funds on that chain (manage a pool, vault, etc.), and to perform privileged actions (burn, mint, move funds out of the vault, etc.). This is required for general-purpose cross-chain smart contracts, as a core feature of smart contracts is to manage assets autonomously. On Ethereum for example, a smart contract has an address and can hold any asset like an External Owned Address (EOA, normal user account). This ability enables many powerful applications such as AMM pools, lending/borrowing pools, etc., where users pool their assets and let smart contracts manage them according to a smart contract’s predetermined rules. In order to hold an account, ZetaChain needs to have a private key. To avoid a single point of failure (single location of the private key, single dealer in generating the key), ZetaChain needs a distributed threshold signature scheme. This is also needed to support non-smart-contract chains such as Bitcoin, Dogecoin, or smart-contract platforms that are expensive to verify multi-sig. To avoid any single point of failure, ZetaChain uses state-of-the-art multi-party threshold signature scheme (TSS) [7, 8] based on implementations from THORChain TSS [15] and Binance tss-lib [12]. To the outside world, the ZetaChain validators collectively possess a single ECDSA/EdDSA private key, public key, and address, and the signature signed by ZetaChain can be verified efficiently and natively by standard ECDSA/EdDSA verification procedure by the connected blockchains. Internally, the private key is generated without a dealer, and the private key is distributed in all the validators. At no time is a single entity or a minority of validators able to piece together the private key and sign messages on behalf of the whole network. The key generation and signing procedures are done by Multi-Party Computation (MPC) which reveal no secret of any participating node. Because ZetaChain can hold a TSS key and address, ZetaChain can support smart contracts that can manage native vaults/pools on connected chains including Bitcoin. This effectively adds smart contract capabilities to the Bitcoin network, and potentially other non-smart contract blockchains. The TSS employed by ZetaChain gives the performance and convenience of hot wallet with cold wallet level security. See Figure 3 for an illustration. Figure 3. Leaderless TSS Keygen and Keysign Overview To sign in a decentralized manner, ZetaChain employs a multi-party -threshold ECDSA scheme based on [7, 8]. This leaderless Threshold Signature Scheme (TSS) performs key generation and signing in a distributed fashion. That is, no single validator or outside actor has access to the complete private key at any point in time, and no private information is leaked in key generation or signing. For efficiency, ZetaChain employs batched signing and parallel signing to improve signers throughput. 4.4. Cross-Chain Smart Contracts and Zeta Virtual Machine The ZetaChain hosts an Ethereum Virtual Machine (EVM) compatible execution layer called ZetaChain EVM. Aside from supporting all features of EVM and normal interactions with EVM (contract creation, contract interaction, composition of contracts, etc), the distinguishing feature of ZetaChain EVM is that ● contracts on ZetaChain EVM can be called from external chains ● contracts on ZetaChain EVM can generate outbound transaction on external chains These two additional features make the ZetaChain EVM a general purpose programmable platform that supports cross-chain transactions that alter states in different chains atomically and in a single step . 4.4.1. Challenges in General Purpose Cross-Chain Transaction There are two key challenges in designing a general-purpose cross-chain transaction platform: asynchrony and atomicity. The first challenge is that communication between chains is necessarily via message passing and inherently asynchronous between heterogeneous chains. This means unlike smart contracts on a single chain (such as EVM), querying or changing the state of another chain is asynchronous. This precludes the common convenient synchronous function calls from cross-chain smart contracts. The cross-chain smart contract programming model thus is best considered as a finite state machine, where state change is triggered by the messages (observations) from external chains. The app contract thus will be structured as a distributed event-driven state machine triggered by messages. This is quite a more complicated programming model from the synchronous model of single chain smart contract. The second challenge is the atomicity of cross-chain transactions. As cross-chain transactions involve altering states on multiple chains, if one part of the state change fails, all previous state changes need to be reverted. Blockchains reverts are powerful mechanisms to maintain atomicity, but no blockchain is built with consideration such that revert is conditional on what happened on another blockchain. To maintain cross-chain transaction atomicity, any cross-chain solution must adequately handle reverts, otherwise cross-chain applications will be too onerous to reason about and build. In this paper we explore a viewpoint of hybrid UTXO and account-based approach, playing to the strengths of each. Essentially, we use UTXO to represent and track external blockchain transactions, and use account-based smart contracts for logic and managing shared global states. We treat observed external events as a “synthetic” UTXO. A UTXO includes the amount of ZETA coin (burned), amount of another coin (optional, for example, BTC on the Bitcoin network where it's impossible to issue ZETA coin), and a script msg (roughly equivalent to a message or function call on Ethereum). The smart contract on ZetaChain runs the msg and generates an Event that tries to “spend” the UTXO on ZetaChain. The Event is then picked up by ZetaClient signers and they will sign a transaction to an external chain. The ZetaChain Virtual Machine and ZetaClient will validate certain invariants, one of which is that the output ZETA must be equal to the input ZETA in the UTXO. Once the outbound transaction is confirmed and observed, the UTXO is marked as “spent” and deleted from the state machine. If the outbound transaction fails (insufficient gas, etc.), the UTXO is marked as “revert” and refunds of ZETA and/or associated coins are refunded on the source chain. When the refund is confirmed then the UTXO is deleted from the state machine. See Figure 4 for an illustration. We use the synthetic UTXO model for its accountability, simplicity, and scalability while avoiding the key limitation of UTXO which is the expressiveness of its scripting, and awkwardness in certain important applications (one TX per block in AMM). Figure 4. Hybrid UTXO-account flow. 4.4.2. Universal Smart Contract ZetaChain introduces Universal Smart Contracts, a more efficient alternative to typical cross-chain messaging (CCMP) protocols. This model simplifies development by centralizing application logic and state into a single contract on ZetaChain's EVM. This avoids the expense, latency, and complexity of synchronizing state across distributed contracts on multiple chains, a common issue with CCMP that also complicates handling reverts and precludes chains without smart contracts (like Bitcoin). A universal smart contract is a ZetaChain EVM contract that can: ● be arbitrarily programmed. ● directly control assets on external chains. ● be called from external chains. ● call contracts and transfer assets to external chains. Foreign assets like ETH, BTC, or USDC are controlled by ZetaChain's TSS address on external chains and are represented on ZetaChain EVM as ZRC-20 tokens. Any ZetaChain EVM contract can achieve universal functionality by implementing the UniversalContract interface and interacting with ZRC-20s. interface UniversalContract { function onCall( MessageContext calldata context, address zrc20, uint256 amount, bytes calldata message ) external; } 1. Calling a Universal Smart Contract from External Chains An inbound call is initiated when a user sends assets to a Gateway Contract (or TSS address on a non smart contract chain like Bitcoin) on an external chain with a memo specifying the destination ZetaChain EVM contract and a message. ZetaChain's network observes this transaction and invokes the onCall function on the specified contract, populating it with the context of the call (origin chain, sender), the ZRC-20 address of the asset, the amount, and the message. The contract then executes its logic. If the ZetaChain EVM execution reverts, the protocol automatically creates a transaction to refund the user. 2. Calling an External Chain Smart Contract from a ZetaChain EVM Contract ZetaChain EVM contracts can initiate outbound transactions—both asset transfers and arbitrary function calls—through the Gateway ZetaChain EVM contract. This enables two-way communication and orchestration of multi-chain logic. // A simplified interface for ZetaChain's Gateway on zEVM interface IGatewayZEVM { function call(...) external; function withdraw(...) external; function withdrawAndCall(...) external; } To make an outbound call, the ZetaChain EVM contract must pay the destination chain's gas fee using the corresponding gas ZRC-20 token. The process involves calculating the fee, transferring it from the user, approving the Gateway, and invoking the appropriate Gateway function (call, withdraw, or withdrawAndCall). // Sample zEVM function to call an external contract function callExternalContract( bytes memory receiver, // External contract address address gasZRC20, // Destination chain's gas ZRC-20 bytes calldata message // Encoded external function call ) external { // 1. Calculate gas fee for the outbound transaction. uint256 gasLimit = 100000; (, uint256 gasFee) = IZRC20(gasZRC20).withdrawGasFeeWithGasLimit(gasLimit); // 2. Collect gas fee from the user and approve the Gateway. require(IZRC20(gasZRC20).transferFrom(msg.sender, address(this), gasFee)); IZRC20(gasZRC20).approve(address(gateway), gasFee); // 3. Execute the cross-chain call via the Gateway. gateway.call( receiver, gasZRC20, message, CallOptions({gasLimit: gasLimit, isArbitraryCall: true}), RevertOptions({revertAddress: address(this), ...}) ); } ZetaChain provides robust revert handling. If an outbound call fails, the protocol automatically triggers an onRevert function on a developer-specified contract, allowing for graceful error handling and fund recovery. 3. Example: Cross-Chain Swap Application A cross-chain swap application demonstrates this model's power, enabling a user to exchange Token A on Chain X for Token B on Chain Y in a single transaction, with all logic managed by one ZetaChain EVM contract. Handling Inbound Swaps (onCall) The onCall function serves as the entry point, triggered by a user's deposit on a connected chain. It decodes the user's intent, executes the swap logic, and initiates the outbound transfer. // Entry point for incoming cross-chain transactions function onCall( MessageContext calldata context, address inputZRC20, uint256 amount, bytes calldata message // Contains target token and recipient ) external override onlyGateway { // 1. Decode message to get the target token and recipient. (address targetZRC20, bytes memory recipient, ...) = abi.decode(message, ...); // 2. Swap input token for the target token and for gas on zEVM. (uint256 outputAmount, address gasZRC20, uint256 gasFee) = handleGasAndSwap(...); // 3. Initiate the outbound transfer of swapped tokens. withdraw(recipient, outputAmount, targetZRC20, gasZRC20, gasFee); } Executing the Outbound Transfer (withdraw) After the swap on ZetaChain EVM, the withdraw function sends the resulting tokens to the recipient on the destination chain by calling the Gateway. // Sends swapped tokens to the destination chain function withdraw( bytes memory recipient, uint256 outputAmount, address targetZRC20, address gasZRC20, uint256 gasFee ) internal { // 1. Approve the Gateway to spend the gas and target tokens. IZRC20(gasZRC20).approve(address(gateway), gasFee); IZRC20(targetZRC20).approve(address(gateway), outputAmount); // 2. Call the Gateway to withdraw tokens to the recipient. gateway.withdraw( recipient, outputAmount, targetZRC20, RevertOptions({revertAddress: address(this), ...}) ); } This illustrates how the universal model centralizes logic, freeing the developer from managing multi-chain deployments and low-level messaging, while the ZetaChain protocol handles the underlying complexity. Note 1: Contracts that don't need to be called from external chains need not implement the UniversalContract interface. Note 2: The capabilities of universal contracts are dependent on the available primitives, like the ZRC-20 standard for fungible tokens. Note 3: Deploying logic and state to a single contract on ZetaChain EVM, with protocol-handled reverts, makes building universal dApps significantly easier than message-passing alternatives. Note 4: This architecture supports non-smart contract chains like Bitcoin, as no contracts need to be deployed on the external chains. 4.4.3. Universal Smart Contracts vs. Messaging While both mechanisms can support many types of applications, they offer fairly significant differences in the architecture those applications would adopt. More complicated dApps may prefer Universal Smart Contracts because the logic & state is in a single place, whereas with messaging, you must broadcast messages and state sync across many contracts on different chains, which can lead to more attack surface and more gas fees (each message requires additional gas to be paid, and the number of messages you must send to maintain a full state sync scales). In other words, Universal Smart Contracts behave, for developers, as if all assets were on one chain (see Figure 5). Figure 5. Universal smart contract-based application. Note that there is a single contract that receives input, writes output, maintains state, and orchestrates external assets for the application. The number of external transactions required for a Universal dApp increases only based on the required outbound transactions, like withdrawing assets to an external chain's address Common applications like Uniswap V2/V3, Curve, Aave, Compound, and so on that have been audited and battle-tested on Ethereum/EVM can easily be deployed and built on top of in ZetaChain's Universal Smart Contracts. One can extend these applications by adding in compatibility with ZRC-20, but those changes are minimal and the majority of logic may remain the same, and users may interact with these applications in single-step transactions just as they would on Ethereum (or by calling them from external chains). On the other hand, with messaging, in many situations (especially those that are more complex), a developer must recreate the logic in a completely different, asynchronous messaging and state-sync system; messaging cannot leverage existing work in the same way. ZRC-20 can easily support Bitcoin/Cardano/XRP which do not have capability or efficiency to support general purpose smart contracts for applications like swapping, lending, etc. Messaging cannot work for these chains, because messaging requires smart contracts on any connected chain. Figure 6. Messaging-based application. Note that for contracts to stay in sync across connected chains, the number of messages required increases exponentially with the number of chains involved. Messaging generally makes sense in simpler use cases between 2 or just a few chains, or where state should heavily be based in one chain, and sent or interacted with from other chains. Application-specific bridges, for example, where the goal is simply to get data/value into one chain, could make sense to build with messaging. Applications that must utilize contracts on external chains may also need a messaging-based component. For more complex applications, the number of messages (and thus gas/transactions) required to synchronize state across multiple chains can increase exponentially with the number of chains involved (see Figure 6). For example, managing a vault or lending protocol with assets across many chains could be difficu
프로젝트로 돌아가기