owned this note
owned this note
Published
Linked with GitHub
## Background
### Requirement
Currently, cdk-erigon follows zkEVM execution rules, which differ slightly from standard EVM (see detailed comparison [here](https://docs.polygon.technology/zkEVM/architecture/protocol/etrog-upgrade/?h=zkevm+is#zkevm-is-almost-type-2)).
In the near future, the client will need to support transaction execution that adheres to standard EVM execution, including the instruction set and precompiles. Essentially, we will need a single client capable of supporting two modes simultaneously for different chains:
* zkEVM
* Standard EVM
### Problem
In zkEVM, chain rules are updated via hard forks, such as Etrog and Elderberry. A hard fork can influence two aspects:
* Core EVM execution that happens in EVM, e.g., instruction set, precompiles
* Pre/post EVM execution, e.g., GER update, effective gas calculation, dynamic gas calculation
The challenge arises when using a single client to support chains running different rules in these two dimensions.
For example, consider running two chains, zkEVM and a CDK chain, using cdk-erigon in its current form. Now we would like to enable dynamic gas calculation (EIP-1559), which was introduced in the London hard fork, for both chains. In order to do so, London HF needs to be enabled in the chainspec of both chains. However, because core EVM execution is prioritized to follow zkEVM, we can't configure the CDK chain to follow London EVM execution.
**Case 1: Prioritizing zkEVM HF** (cdk-erigon in its current state)
Chain-spec:
* London=true
* Elderberry=true
| Chain | Desired core EVM execution | Actual core EVM execution | Dynamic gas calculation |
|-----------|-----------------------------|---------------------------|-------------------------|
| zkEVM | Elderberry | Elderberry | Yes |
| CDK chain | London | Elderberry | Yes |
**Case 2: Prioritizing Ethereum HF**
If we update the code to prioritize the EVM execution inherited from Ethereum HF instead, it becomes impossible to use Elderberry EVM execution for zkEVM.
Chain-spec:
* London=true
* Elderberry=true
| Chain | Desired core EVM execution | Actual core EVM execution | Dynamic gas calculation |
|-----------|-----------------------------|---------------------------|-------------------------|
| zkEVM | Elderberry | London | Yes |
| CDK chain | London | London | Yes |
In summary, the existing chain spec configuration is not flexible enough to configure chains with different execution rules.
## Proposed Solution
We will introduce a new hard fork, named `Normalcy` (suggestions for a better name are welcome), which only influences core EVM executions. When `Normalcy` is enabled, the client will follow the core EVM execution rules from Ethereum HF. When disabled, the client will follow zkEVM execution rules. To enable the `Normalcy` HF for a new CDK chain, we simply need to set `normalcyBlock` to 0 in chainspec file (see an example of chainspec file [here](https://github.com/0xPolygonHermez/cdk-erigon/blob/zkevm/zk/examples/dynamic-configs/dynamic-hermez-cardona-chainspec.json)).
Using the same example as above, the tables are updated as follows:
**Case 1**
* London=true
* Elderberry=true
* Normalcy=false
| Chain | Desired core EVM execution | Actual core EVM execution | Dynamic gas calculation |
|-----------|-----------------------------|---------------------------|-------------------------|
| zkEVM | Elderberry | Elderberry | Yes |
**Case 2**
* London=true
* Elderberry=true
* Normalcy=true
| Chain | Desired core EVM execution | Actual core EVM execution | Dynamic gas calculation |
|-----------|-----------------------------|---------------------------|-------------------------|
| CDK chain | London | London | Yes |
**Case 3**
* London=false
* Elderberry=true
* Normalcy=false
| Chain | Desired core EVM execution | Actual core EVM execution | Dynamic gas calculation |
|-----------|-----------------------------|---------------------------|-------------------------|
| zkEVM chain | Elderberry | Elderberry | No |
**Case 4**
* Berlin=true
* London=false
* Elderberry=true
* Normalcy=true
| Chain | Desired core EVM execution | Actual core EVM execution | Dynamic gas calculation |
|-----------|-----------------------------|---------------------------|-------------------------|
| CDK chain | Berlin | Berlin | No |
### Summary
With this new Normalcy hardfork, a CDK chain can be configured to use the EVM from any Ethereum hardfork while maintaining its compatibility with the bridge and AggLayer, if there are any upgrades. Conversely, zkevm will be able to reuse pre/post execution changes from Ethereum hardforks (e.g., dynamic gas) while retaining its customized EVM execution.