ZKsync 백서

ZKsync

원문

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

f the calls fails. Call status You can also track the individual status of a call inside a bundle using the bundle hash and index of the call in the bundle. function callStatus ( bytes32 bundleHash , uint256 callIndex ) external view returns ( CallStatus ); enum CallStatus { Unprocessed , Executed , Cancelled } A call can either be: Unprocessed : The call is not processed yet. Executed : The call was successfully executed. Cancelled : The call was cancelled during unbundling. When a call fails What happens depends on which path is used: executeBundle is atomic. If any call fails, the entire transaction reverts and none of the calls are marked as executed. verifyBundle only checks that the bundle message was included. It does not execute any calls, so it can be used first when you want to inspect or manage a bundle before execution. unbundleBundle is the recovery path for non-atomic handling. After a bundle has been verified, the authorized unbundler can choose call-by-call statuses and process the bundle incrementally. This means you cannot partially succeed through executeBundle , but you can still handle a problematic bundle after verification by using unbundleBundle to: execute the calls that are valid cancel the calls that should not run leave other calls untouched until a later unbundling step In practice, this is the flow to use when one call in a bundle is malformed or expected to fail, but you still want to recover and process the rest of the bundle in a controlled way. Overview Learn about how ZKsync Connect enables interoperable ZKsync chains. Crosschain Asset Transfers Learn how crosschain asset transfers work. ## /zksync-network/zksync-connect/crosschain-asset-transfers ZKsync Docs Crosschain Asset Transfers Learn how crosschain asset transfers work. Crosschain asset transfers are not yet live on any mainnet or testnet chains. They will be added in a future protocol upgrade. What are crosschain asset transfers? Crosschain asset transfers let you move supported assets directly from one ZKsync chain to another ZKsync chain through ZKsync Connect, without first withdrawing to L1 and bridging again. How do they work? With ZKsync Connect crosschain asset transfers, assets are tracked natively across ZKsync chains. The transfer is processed through the Asset Router and Native Token Vault contracts, with asset accounting enforced by asset tracker contracts. Assets are tracked through asset tracker contracts deployed on L1 and the participating L2 chains. The asset transfer contracts ensure that no chain is able to transfer more assets than it has. For users, this means the transfer stays inside the ZKsync ecosystem and does not require withdrawing to L1 and then re-bridging to another chain. Assets are transferred via transaction bundles. On the destination chain, the InteropHandler executes the bundle by calling the L2AssetRouter , which finalizes the transfer. Different assets use different transfer mechanics. For standard ERC20 tokens, the tokens are burned on the source chain and minted on the destination chain. For other supported assets, the Asset Router calls the asset’s handler to perform the appropriate transfer logic. What can I transfer? You can transfer: Standard fungible ERC20-style tokens supported by the Native Token Vault and Asset Router. The chain’s base token, including ETH on ETH-based chains, if sent to a contract. Arbitrary token standards are not supported automatically. For example, ERC721 and ERC1155 assets are not supported by the Asset Router unless custom bridging logic has been added for them. Can I transfer an asset without a special contract? Yes. For standard crosschain asset transfers, the interop recipient is the L2AssetRouter , not the final user recipient. This means the final recipient can be either an EOA or a contract. A contract only needs to implement IERC7786Recipient if you want to send a general interop message or transaction bundle directly to that contract, rather than using the Asset Router transfer flow. Is there any setup required? Before an asset can be transferred, it must be registered with the asset tracking and handler infrastructure. This registration only needs to happen once per asset. Until that migration happens, the asset tracker flow will not recognize the token for crosschain transfers. If the token is bridged from the L1, this migration will happen automatically. Transaction Bundles Learn about how transaction bundles work. Messaging Learn about how send and verify messages with ZKsync Connect. ## /zksync-network/zksync-connect/messaging ZKsync Docs Messaging Learn about how send and verify messages with ZKsync Connect. Interop messaging enables sending and verifying messages across ZKsync chains. An interop message consists of arbitrary data and has two simple properties: Anyone can send a message. Anyone can verify that a given message was successfully sent on some chain. One example use case for interop messaging would be to unlock experiences on a chain based on activities on another chain. Sending a message To send a message, you can call the sendToL1 function on the L1Messenger contract, which is pre-deployed on every ZKsync chain at address 0x00..008008 : //SPDX-License-Identifier: Unlicense pragma solidity ^0.8.28 ; interface IL1Messenger { function sendToL1 ( bytes calldata _message) external returns ( bytes32 ); } contract InteropSendMessage { address constant L2_TO_L1_MESSENGER_SYSTEM_CONTRACT_ADDR = 0x0000000000000000000000000000000000008008 ; IL1Messenger public l1Messenger = IL1Messenger (L2_TO_L1_MESSENGER_SYSTEM_CONTRACT_ADDR); function sendMessage ( bytes calldata _message) external { l1Messenger. sendToL1 (_message); } } The message itself has no destination chain or address. It’s simply a payload created by a user or contract that gets broadcast. There is no expiration for when messages can be verified. They remain verifiable indefinitely. The function name sendToL1 was kept from previous versions for simplicity, although it does not restrict messages from only being verified on the L1. These messages are the foundation to unlock more complex crosschain activities in the future, like bridging assets and operate with contracts across different chains. Lifecycle of sending a message Send a Message: The message is sent via the sendToL1 method in the L1Messenger contract. Batch created: The transaction gets included in a batch. Chain-batch root updated: The chain-batch root (which includes the log for the message) is added to the global message root. The MessageRoot is a contract that collects messages from different chains and aggregates them into a single Merkle tree. Event emitted: The MessageRoot contract emits an event indicating that the interop root was updated. Event detected: EthWatch detects the event from a ZKsync chain, stores it in its database,and includes it in the next batch’s bootloader state. New Root gets stored: The bootloader calls the L2InteropRootStorage contract to update its stored interop roots. Dependency verification: The latest batch’s dependency roots are verified against the MessageRoot . At this point, the interop root for the batch is confirmed. Verifying a message Messages can be verified using the proveL2MessageInclusionShared method in the L2 message verification contract deployed at 0x..10009 on each ZKsync chain. //SPDX-License-Identifier: Unlicense pragma solidity ^0.8.28 ; interface IMessageVerification { struct L2Message { uint16 txNumberInBatch; address sender; bytes data; } function proveL2MessageInclusionShared ( uint256 _sourceChainId, uint256 _l1BatchNumber, uint256 _l2MessageIndex, L2Message calldata _l2MessageData, bytes32 [] calldata _proof ) external view returns ( bool ); } contract InteropVerification { address constant L2_MESSAGE_VERIFICATION_ADDRESS = 0x0000000000000000000000000000000000010009 ; IMessageVerification public l2MessageVerifier = IMessageVerification (L2_MESSAGE_VERIFICATION_ADDRESS); function checkVerification ( uint256 _sourceChainId, uint256 _l1BatchNumber, uint256 _l2MessageIndex, IMessageVerification . L2Message calldata _l2MessageData, bytes32 [] calldata _proof ) external view returns ( bool ) { return l2MessageVerifier. proveL2MessageInclusionShared ( _sourceChainId, _l1BatchNumber, _l2MessageIndex, _l2MessageData, _proof ); } } Lifecycle of verifying a message Proof Submission: The user calls proveL2MessageInclusionShared at the L2_MESSAGE_VERIFICATION_ADDRESS ( 0x..10009 ), supplying the message data and a proof of inclusion. Note, that this step could be done in the same batch as the dependency verification. Final Verification: The L2InteropRootStorage contract is triggered to verify the corresponding interop root inclusion on the chain where the proof was submitted. For more detail about how interoperability works at the protocol level, visit the protocol specifications documentation. Crosschain Asset Transfers Learn how crosschain asset transfers work. ZKsync OS Overview Learn about the ZKsync OS Developer Preview testnet and its architecture. ## /zksync-network/zksync-os ZKsync Docs ZKsync OS Overview Learn about the ZKsync OS Developer Preview testnet and its architecture. The ZKsync OS Developer Preview testnet is a new environment that runs on the latest architecture introduced in the Atlas upgrade . It includes all major components released in that upgrade — ZKsync OS , the new Sequencer , and the Airbender prover — giving developers early access to the full next-generation ZK Stack. This testnet allows builders to deploy contracts, profile system performance, and explore how the ZK Stack has evolved across execution, sequencing, and proving. Overview ZKsync OS is the new operating system of the ZK Stack. It defines the system-level state transition function of a chain and supports multiple Execution Environments (EEs) . Unlike earlier implementations, ZKsync OS unifies execution and proving logic in one codebase and compiles it to two targets — x86 for the sequencer runtime and RISC-V for the Airbender proving system. The Developer Preview testnet runs ZKsync OS alongside the new Sequencer and Airbender prover , providing a complete environment for testing the latest stack. Architecture The core protocol is organized into two primary layers: Execution layer: defines transaction logic, memory handling, and IO. It computes new state from the previous block state and inputs. Proving layer: generates ZK proofs that attest to the correctness of that state transition. ZKsync OS is implemented in Rust and compiled to two targets: x86: used by the Sequencer to execute transactions RISC-V: used by the Airbender prover to generate ZK proofs of correctness This “one program, two targets” model ensures what you execute is what you prove , eliminating discrepancies between runtime and proof generation and reducing the audit surface. Execution and proving operate as decoupled services (sequencer vs. prover) while sharing the exact same program and semantics. Components ZKsync OS The core of the system. ZKsync OS provides a modular execution framework that supports multiple execution environments and defines the rules for state transitions. Bootloader : initializes the system and coordinates transaction execution. Execution Environments : interpreters that run user contracts and system logic. System Layer : handles low-level IO (storage, events, L1 messages) and manages memory. The Developer Preview currently supports a fully EVM-equivalent environment , allowing developers to use existing EVM tools (e.g. Foundry, Hardhat, solc) and deploy contracts without modification. Future versions may include EraVM , WASM and native RISC-V environments. Learn more about ZKsync OS in the protocol documentation . Sequencer The new Sequencer , introduced as part of the Atlas upgrade , is designed for: High throughput — sustained >15K TPS in ERC-20 transfer benchmarks Low latency — sub-second inclusion, typically 250–500 ms Modularity — clear separation of execution, API, and proving layers It offloads batching and L1 coordination to asynchronous services, simplifying the execution pipeline and improving resilience. For developers, this means faster transaction processing and easier scaling for custom ZK Stack chains. Airbender Prover Airbender is the proving system used in the Developer Preview testnet. It is a general-purpose, open-source RISC-V zkVM integrated directly with ZKsync OS. Key properties: Efficient hardware utilization — can run on a single GPU. Low cost — proving an ERC-20 transfer costs roughly $0.0001. Fast proofs — Airbender can be scaled horizontally to generate ~1 second block proofs and minutes-to-Ethereum finality . Because both execution and proving compile from the same Rust source, Airbender proves the exact code path executed by ZKsync OS. This reduces audit complexity and guarantees consistency between runtime and proofs. Learn more about Airbender in the protocol documentation . Developer Preview Testnet The Developer Preview testnet includes: ZKsync OS — modular execution layer with full EVM equivalence. New Sequencer — redesigned high-performance execution engine. Airbender — integrated real-time RISC-V prover. Developers can use this testnet to: Deploy and test contracts using familiar EVM tooling Benchmark transaction throughput and latency Integration test for infrastructure tools Evaluate how the new architecture supports specific workloads Messaging Learn about how send and verify messages with ZKsync Connect. Network Details Connect to ZKsync OS Developer Preview testnet ## /zksync-network/zksync-os/network-details ZKsync Docs Network Details Connect to ZKsync OS Developer Preview testnet Add ZKsync OS Developer Preview to your MetaMask wallet You can add ZKsync OS Developer Preview to your MetaMask wallet using the button below: Add ZKsync OS Developer Preview If you are using a different in-browser wallet, the button above may also work for them. Manually add ZKsync OS Developer Preview To manually add ZKsync OS Developer Preview as a custom network in your wallet, follow these steps: Find the “Add Network” option in your wallet (in MetaMask, you can find this in the networks dropdown). Click on “Add Network" and "Add network manually". Fill in the following details for the ZKsync OS Developer Preview testnet: Network details Property Value Network Name ZKsync OS Developer Preview RPC URL https://zksync-os-testnet-alpha.zksync.dev/ WebSocket URL wss://zksync-os-testnet-alpha.zksync.dev/ws Chain ID 8022833 Currency Symbol ETH Block Explorer URL https://zksync-os-testnet-alpha.staging-scan-v2.zksync.dev/ Explorer Verification API https://block-explorer-api.zksync-os-testnet-alpha.zksync.dev/api Get funds for your wallet Once you have your wallet connected to the ZKsync OS Developer Preview environment, you can bridge testnet ETH from Sepolia Testnet. You can get testnet funds on Sepolia from one of many testnet faucets . Bridging testnet ETH The easiest way to bridge funds to the testnet is by using the ZKsync OS Portal to bridge testnet ETH over. You can also bridge funds in your terminal with cast or in a script using zksync-js as shown in the examples below. Bridging with cast export BRIDGEHUB_ADDRESS = 0xc4fd2580c3487bba18d63f50301020132342fdbd export CHAIN_ID = 8022833 export SEPOLIA_RPC =< YOUR_SEPOLIA_RPC_ENDPOINT > export ADDRESS =< YOUR_WALLET_ADDRESS > export VALUE_TO_BRIDGE =< AMOUNT_TO_BRIDGE_IN_WEI > cast send -r $SEPOLIA_RPC $BRIDGEHUB_ADDRESS "requestL2TransactionDirect((uint256,uint256,address,uint256,bytes,uint256,uint256,bytes[],address))" "( $CHAIN_ID , $VALUE_TO_BRIDGE , $ADDRESS ,50,0x,300000,800,[], $ADDRESS )" --value $VALUE_TO_BRIDGE --private-key= $PRIVATE_KEY Bridging with zksync-js You can find examples for bridging with ethers or viem in the zksync-js docs . ZKsync OS Overview Learn about the ZKsync OS Developer Preview testnet and its architecture. Developer Quickstart Getting starting developing with ZKsync OS ## /zksync-network/zksync-os/quickstart ZKsync Docs Developer Quickstart Getting starting developing with ZKsync OS You can use all standard EVM tooling for ZKsync OS. You can find instructions for bridging testnet ETH to ZKsync OS Developer Preview testnet in the Network Details page. To get started with Foundry or Hardhat, follow the steps below: Foundry Hardhat 3 with Viem Hardhat 3 with Ethers Create a new foundry project: forge init Counter cd Counter Build the project forge build Set your private key for deploying: export TESTNET_PRIVATE_KEY = "0x..." Deploy the contract: forge script script/Counter.s.sol --rpc-url https://zksync-os-testnet-alpha.zksync.dev --broadcast --skip-simulation --private-key $TESTNET_PRIVATE_KEY Set the number value: cast send 0x < YOUR_CONTRACT_ADDRES S > \ "setNumber(uint256)" 5 \ --rpc-url https://zksync-os-testnet-alpha.zksync.dev \ --private-key $TESTNET_PRIVATE_KEY Get the latest number value: cast call 0x < YOUR_CONTRACT_ADDRES S > \ "number()" \ --rpc-url https://zksync-os-testnet-alpha.zksync.dev Verify the contract: forge verify-contract \ --chain-id 8022833 \ --verifier custom \ --verifier-url https://block-explorer-api.zksync-os-testnet-alpha.zksync.dev/api \ 0x<YOUR_CONTRACT_ADDRESS> \ src/Counter.sol:Counter Create a new project folder mkdir hardhat-example cd hardhat-example Initialize a new Hardhat 3 project with Node Test Runner and Viem. npx hardhat --init Add ZKsync OS to the hardhat.config.ts file and configure the ignition required confirmations. hardhat.config.ts ignition : { requiredConfirmations : 1 , }, networks : { zksyncOS : { type : 'http' , chainType : 'generic' , url : 'https://zksync-os-testnet-alpha.zksync.dev' , accounts : [ configVariable ( 'TESTNET_PRIVATE_KEY' )], }, }, Add your private key to the keystore as TESTNET_PRIVATE_KEY . npm yarn pnpm bun npx hardhat keystore set TESTNET_PRIVATE_KEY Compile and deploy the example contract. npm yarn pnpm bun npx hardhat compile npm yarn pnpm bun npx hardhat ignition deploy ignition/modules/Counter.ts --network zksyncOS Create a new script file in the scripts folder called increment.ts . touch scripts/increment.ts Copy/paste the script below. increment.ts import { network } from 'hardhat' ; import { type Abi, defineChain } from 'viem' ; const CONTRACT_ADDRESS = '0x7Be3f2d08500Fe75B92b9561287a16962C697cb7' ; const { viem } = await network. connect ( 'zksyncOS' ); const zksyncOS = defineChain ({ id: 8022833 , name: 'ZKsync OS' , network: 'zksyncOS' , nativeCurrency: { name: 'Ether' , symbol: 'ETH' , decimals: 18 }, rpcUrls: { default: { http: [ 'https://zksync-os-testnet-alpha.zksync.dev' ] } }, }); const publicClient = await viem. getPublicClient ({ chain: zksyncOS }); const [ senderClient ] = await viem. getWalletClients ({ chain: zksyncOS }); if ( ! senderClient) throw new Error ( 'No wallet client. Set TESTNET_PRIVATE_KEY in hardhat config.' ); const counterContract = await viem. getContractAt ( 'Counter' , CONTRACT_ADDRESS , { client: { public: publicClient, wallet: senderClient }, }); const initialCount = await publicClient. readContract ({ address: CONTRACT_ADDRESS , abi: counterContract.abi as Abi , functionName: 'x' , }); console. log ( 'Initial count:' , initialCount); const tx = await senderClient. writeContract ({ address: CONTRACT_ADDRESS , abi: counterContract.abi as Abi , functionName: 'inc' , }); await publicClient. waitForTransactionReceipt ({ hash: tx }); console. log (
프로젝트로 돌아가기