Ethereum: Understanding ZkSync System Contracts
and EVM Precompiles
When it comes to deploying and executing smart contracts on the Ethereum network, developers need to choose between two popular approaches: zk-Synched (zS) system contracts and EVM precompiles. In this article, we’ll delve into the differences between these two approaches and explore when each is suitable.
What are ZkSync System Contracts?
ZkSynched system contracts are a new standard for Ethereum smart contract deployment introduced in June 2021. They aim to improve the performance and security of z-Synched deployments by introducing a more efficient and robust way of executing code on the blockchain.
Here’s how it works:
- ZS contracts use the EVM (Ethereum Virtual Machine) under the hood, just like other Ethereum contracts.
- However, ZS contracts have an additional layer of abstraction built into them. They are essentially precompiled assemblies that contain all the necessary code to execute on the blockchain.
- When a developer wants to deploy a contract to zk-Synched, they can use a tool like zkSync or Hardhat to create a zS contract assembly from their code.
What are EVM Precompiles?
EVM precompiles, also known as system contracts
, are similar to ZK-Sync system contracts but operate on top of the EVM instead. They allow developers to compile and deploy Ethereum smart contracts directly to the blockchain without the need for a separate assembly process.
Here’s how it works:
- When a developer wants to deploy a contract, they can use a tool like Web3.js or Truffle Suite to create an EVM precompile from their code.
- The precompile is then stored on a decentralized storage solution, such as InterPlanetary File System (IPFS).
- To execute the contract on the blockchain, the developer needs to link the precompile to a zS contract assembly using a tool like zkSync or Hardhat.
Key differences:
Here are the main differences between ZK-Synched system contracts and EVM precompiles:
| | ZK-Sync System Contracts | EVM Precompiles (system contracts) |
| — | — | — |
|
Execution Context | Requires a separate assembly process | Operates on top of the EVM |
|
Code Abstraction
| Additional layer of abstraction built into the contract | Native to the EVM under the hood |
|
Storage Requirements
| Requires separate storage solutions (e.g., zS contracts) | No need for separate storage solutions |
When to choose ZK-Synched system contracts?
ZK-Sync system contracts are a good choice when:
- You want more control over the execution context and code abstraction.
- Your contract requires additional features or optimizations that cannot be achieved through EVM precompiles.
When to choose EVM precompiles (system contracts)?
EVM precompiles (system contracts) are a good choice when:
- You need to deploy your contract directly to the blockchain without a separate assembly process.
- Your contract is small in size and requires minimal optimizations.
In conclusion, while both ZK-Synched system contracts and EVM precompiles can be used for Ethereum smart contract deployment, they have distinct differences in terms of execution context, code abstraction, and storage requirements. By understanding these differences, developers can choose the approach that best suits their needs and goals.