Skip to content

Commit 92f5de4

Browse files
Merge pull request #1432 from matter-labs/sb-sync-draft-v28-with-release-v27
Sync draft-v28 with release-v27
2 parents 8e316d9 + 1b7bfac commit 92f5de4

File tree

72 files changed

+9508
-748
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+9508
-748
lines changed

AllContractsHashes.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -985,19 +985,19 @@
985985
},
986986
{
987987
"contractName": "l1-contracts/GatewayCTMDeployer",
988-
"zkBytecodeHash": "0x010003c110ebc4cf5572ae2c52982fb14feecbd72fd421a0b3c208a9c5baa51d",
988+
"zkBytecodeHash": "0x010003c188a3d77697a3eb00d92b04ca871bfb40564a70949eb662b56546dc9b",
989989
"zkBytecodePath": "/l1-contracts/zkout/GatewayCTMDeployer.sol/GatewayCTMDeployer.json",
990-
"evmBytecodeHash": "0x4228e6a4c6ceb51e8fc7de43555e94ad965e2d81b9a5304eaee00ad20e339033",
990+
"evmBytecodeHash": "0xd22197a6f68f4088e6b82ff4b4bf558245a960a426658d83029de6d7ff17006d",
991991
"evmBytecodePath": "/l1-contracts/out/GatewayCTMDeployer.sol/GatewayCTMDeployer.json",
992-
"evmDeployedBytecodeHash": "0x7a605035a883cbecefe739ff05ee9a4eb4e0c4766ac4ce061096e12281309490"
992+
"evmDeployedBytecodeHash": "0xf26576e2640c73f8ba633df3b2cf56f8187d74920082bc99c86903c4ac4feb64"
993993
},
994994
{
995995
"contractName": "l1-contracts/GatewayTransactionFilterer",
996-
"zkBytecodeHash": "0x010001392a1e41f32a832bc2da5fa2fb3bec2b9a0ed8641e450d6463846f964d",
996+
"zkBytecodeHash": "0x0100013d861a00847ed28ea6f9b3590436b6e5a30fd54ce4003b9bd3b308e21d",
997997
"zkBytecodePath": "/l1-contracts/zkout/GatewayTransactionFilterer.sol/GatewayTransactionFilterer.json",
998-
"evmBytecodeHash": "0x11183032e0669f5240613c9c738d21700f960e9bc81af49392da4b6090fab174",
998+
"evmBytecodeHash": "0x23d1348c63ca21b735fe95c3687319512e56c6b2df1d41a1b8b378312ff9731e",
999999
"evmBytecodePath": "/l1-contracts/out/GatewayTransactionFilterer.sol/GatewayTransactionFilterer.json",
1000-
"evmDeployedBytecodeHash": "0xd758329f4455e69621e02d30c49c9d301f1a143ff687445175053bfe60dd7219"
1000+
"evmDeployedBytecodeHash": "0xa68a869e457533ea13e2bebca4acaafb46dc0d1f4eb638079134e776cb9948b9"
10011001
},
10021002
{
10031003
"contractName": "l1-contracts/GatewayUpgrade",
@@ -1321,11 +1321,11 @@
13211321
},
13221322
{
13231323
"contractName": "l1-contracts/ServerNotifier",
1324-
"zkBytecodeHash": "0x010000b991c3aadeb1b08b89a62875c20809bd6ba6485017e3345f34fdf90069",
1324+
"zkBytecodeHash": "0x010000abf9520e5e2db74ebdf0895d6f76c579d93de6ad238bc25523c7c4fce7",
13251325
"zkBytecodePath": "/l1-contracts/zkout/ServerNotifier.sol/ServerNotifier.json",
1326-
"evmBytecodeHash": "0xbbf56a3820456bc835c2829697ddee0027bbc61b0081a3bd87a1842c481bfc1f",
1326+
"evmBytecodeHash": "0xf0998f4665cca015ddfd981f4d05b6b4b23d7d7107ed60d2b0d140285fe795aa",
13271327
"evmBytecodePath": "/l1-contracts/out/ServerNotifier.sol/ServerNotifier.json",
1328-
"evmDeployedBytecodeHash": "0xc55c47324a3b9ac5f947f21b8e380f66025ececb2f45917713b2938c20e44b00"
1328+
"evmDeployedBytecodeHash": "0x50f16c3a61c78c0c1fc3aa379e4d6c5e0c3fa407d7213cee852956c8e72e1eba"
13291329
},
13301330
{
13311331
"contractName": "l1-contracts/SignedMath",
316 KB
Binary file not shown.
604 KB
Binary file not shown.
Binary file not shown.

docs/README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,21 @@ The order of the files here only roughly represents the order of reading. A lot
3333
- Gateway
3434
- [General overview](./gateway/overview.md)
3535
- [Chain migration](./gateway/chain_migration.md)
36-
- [L1->L3 messaging via gateway](./gateway/messaging_via_gateway.md)
37-
- [L3->L1 messaging via gateway](./gateway/nested_l3_l1_messaging.md)
36+
- [L1->L2 messaging via gateway](./gateway/messaging_via_gateway.md)
37+
- [L2->L1 messaging via gateway](./gateway/l2_gw_l1_messaging.md)
3838
- [Gateway protocol versioning](./gateway/gateway_protocol_upgrades.md)
3939
- [DA handling on Gateway](./gateway/gateway_da.md)
40+
- EVM emulation
41+
- [Technical overview](./evm_emulation/technical_overview.md)
42+
- [Gas emulation](./evm_emulation/evm_gas_emulation.md)
43+
- [Differences from EVM (Cancun)](./evm_emulation/differences_from_cancun_evm.md)
44+
- [EVM predeploys list](./evm_emulation/evm_predeploys_list.md)
4045
- Upgrade history
41-
- [Gateway upgrade diff](./upgrade_history/gateway_preparation_upgrade/gateway_diff_review.md)
42-
- [Gateway upgrade process](<./upgrade_history/gateway_preparation_upgrade/upgrade_process_(no_gateway_chain).md>)
46+
- Gateway
47+
- [Gateway upgrade diff](./upgrade_history/gateway_preparation_upgrade/gateway_diff_review.md)
48+
- [Gateway upgrade process](<./upgrade_history/gateway_preparation_upgrade/upgrade_process_(no_gateway_chain).md>)
49+
- EVM emulator
50+
- [Upgrade process and changes](./upgrade_history/v27_evm_emulation/v27-evm-emulation.md)
4351

4452
![Reading order](./img/reading_order.png)
4553

@@ -57,8 +65,8 @@ The repository contains the following sections:
5765

5866
This section is for auditors of the codebase. It includes some of the important invariants that the system relies on and which if broken could have bad consequences.
5967

60-
- Assuming that the accepting CTM is correct & efficient, the L1→GW part of the L1→GW→L3 transaction never fails. It is assumed that the provided max amount for gas is always enough for any transaction that can realistically come from L1.
68+
- Assuming that the accepting CTM is correct & efficient, the L1→GW part of the L1→GW→L2 transaction never fails. It is assumed that the provided max amount for gas is always enough for any transaction that can realistically come from L1.
6169
- GW → L1 migration never fails. If it is possible to get into a state where the migration is not possible to finish, then the chain is basically lost. There are some exceptions where for now it is the expected behavior. (check out the “Migration invariants & protocol upgradability” section)
6270
- The general consistency of chains when migration between different settlement layers is done. Including the feasibility of emergency upgrades, etc. I.e. whether the whole system is thought-through.
63-
- Preimage attacks in the L3→L1 tree, we apply special prefixes to ensure that the tree structure is fixed, i.e. all logs are 88 bytes long (this is for backwards compatibility reasons). For batch leaves and chain id leaves we use special prefixes.
71+
- Preimage attacks in the L2→GW→L1 tree, we apply special prefixes to ensure that the tree structure is fixed, i.e. all logs are 88 bytes long (this is for backwards compatibility reasons). For batch leaves and chain id leaves we use special prefixes.
6472
- Data availability guarantees. Whether rollup users can always restore all their storage slots, etc. An example of a potential tricky issue can be found in “Security notes for Gateway-based rollups” [in this document](./gateway/gateway_da.md).
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# General differences from Ethereum
2+
3+
This feature allows EVM emulation on top of EraVM. This mode is not fully equivalent to native EVM and is limited by the EraVM design. This page describes the known differences between emulation and EVM (Cancun).
4+
5+
## Gas behavior differences
6+
7+
- EVM emulation is executed on top of EraVM and all transactions start in EraVM environment. So gas and gaslimit values signed in the transaction correspond to the native **EraVM** gas, not **EVM** gas. For that reason presigned/keyless transactions created for Ethereum may be not compatible with ZK Chains. For detailed info: [Gas emulation](./evm_gas_emulation.md).
8+
- Our “Intrinsic gas costs” are different from EVM.
9+
- We do not implement the gas refunds logic from **EVM**. Because users pay for EraVM gas and EVM gas is virtual, we use EraVM gas refunds logic instead of EVM one. It does not affect contracts behavior (refunds happen in the end of transaction).
10+
- We do not charge EVM gas for tx calldata.
11+
- Access lists are not supported (EIP-2930).
12+
13+
## Limitations
14+
15+
- `DELEGATECALL` between EVM and native EraVM contracts will be reverted.
16+
- Calls to empty addresses in kernel space (address < 2^16) will fail.
17+
- `GASLIMIT` opcode returns the same fixed constant as EraVM and should not be used.
18+
19+
Unsupported opcodes:
20+
21+
- `CALLCODE`
22+
- `SELFDESTRUCT`
23+
- `BLOBHASH`
24+
- `BLOBBASEFEE`
25+
26+
## Precompiles
27+
28+
EVM emulation supports the same precompiles that are supported by EraVM.
29+
30+
## Technical differences
31+
32+
_These changes are unlikely to have an impact on the developer experience._
33+
34+
Differences:
35+
36+
- `JUMPDEST` analysis is simplified. It is not checked that `JUMPDEST` is not a part of `PUSH` instruction.
37+
- No force of call stack depth limit. It is implicitly implemented by 63/64 gas rule.
38+
- Account storage is not destroyed during contract deployment.
39+
- If the deployer's nonce is overflowed during contract deployment, all passed gas will be consumed. EVM refunds all passed gas to the caller frame.
40+
- Nonces are limited by size of `u128`, not `u64`
41+
- During creation of EVM contract by EOA or EraVM contract, emulator does not charge additional `2` gas for every 32-byte chunk of `initcode` as specified in [EIP-3860](https://eips.ethereum.org/EIPS/eip-3860) (since perform `JUMPDEST` analysis is simplified). This cost **is** charged if contract is created by another EVM contract (to keep gas equivalence).
42+
- Code deposit cost is charged from constructor frame, not caller frame. It will be changed in the future.
43+
- Only those accounts that are accessed from an EVM environment become warm (including origin, sender, coinbase, precompiles). Anything that happens outside the EVM does not affect the warm/cold status of the accounts for EVM.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# EVM gas emulation overview
2+
3+
The gas model can be one of the most tricky topics regarding EVM emulation since there are two interacting executions are supported at the same time. This document is intended to explain in more detail how the emulation of the EVM gas works.
4+
5+
## EVM emulation execution flow
6+
7+
From the point of view of EraVM, the EVM emulator is (almost) a regular EraVM contract. This contract is predefined and can be changed only during protocol upgrades. When an EVM contract is called, EraVM invokes the emulator code. The emulator loads the corresponding EVM bytecode and interprets it.
8+
9+
Thus, the emulation is executed on top of EraVM, uses EraVM opcodes and, most importantly, **pays for EraVM operations in native gas (ergs)**.
10+
11+
⚠️ To avoid confusion, native EraVM gas will be referred to as "ergs" further in the text.
12+
13+
This means that **ergs** are used to pay for all operations on EraVM (and therefore on ZK Chains). Gas and gaslimit values signed in user's transactions are specified in **ergs**. All refunds are also made by the virtual machine in ergs.
14+
15+
## EVM gas model emulation
16+
17+
Full EVM gas equivalence is necessary to provide an EVM-compatible environment and meet the assumptions made in contracts. However, the cost of EraVM operations differs, and EVM emulation requires multiple EraVM operations for each EVM operation. As a result, we emulate the EVM gas model.
18+
19+
As mentioned in the previous section, the EVM environment is virtual: it operates on top of EraVM and incurs costs for execution in EraVM ergs. The EVM emulator, however, has its own internal gas accounting system that corresponds to the EVM gas model. Each EVM opcode consumes a predefined amount of gas, according to the EVM specification. And if there is insufficient gas for an operation, the frame will be reverted.
20+
21+
⚠️ EVM gas is used only for compatibility in the EVM emulation mode. Underlying virtual machine is not aware about EVM gas and uses native ergs.
22+
23+
## Ergs to gas conversion rate for gas limit
24+
25+
EVM gas units are not equivalent to EraVM ergs. And both the EVM and EraVM do not provide mechanisms for an EOA or contract to specify how to convert gas from one unit to another. For practical use in the emulator, a predefined constant is used to convert gas limit from one unit to another.
26+
27+
⚠️ Current EraVM -> EVM gas limit conversion ratio is 5:1.
28+
29+
This means that if a user made a call to an EVM contract with 100,000 ergs, the EVM emulator will start execution with 20,000 EVM gas. At the same time, underlying EraVM will have all 100,000 ergs available for use and will refund any unused ergs at the end of transaction.
30+
31+
In the other direction, when calling an EraVM contract from EVM context, if 20,000 gas is provided, the emulator will <ins>try</ins> to pass 100,000 ergs (or less, if amount of ergs left is not enough).
32+
33+
## Out-of-ergs situation
34+
35+
Because EVM gas is virtual and it is not equivalent to EraVM ergs, situations are possible in which emulator has enough EVM gas to continue execution, but encounters `out-of-ergs` panic from EraVM. In this case we simply propagate special internal kind of panic and revert the **whole** EVM frames chain.
36+
37+
⚠️ EVM emulation can only be executed completely, up to returning from the EVM context (incl. EVM reverts), or completely rolled back.
38+
39+
This fact should be taken into account by smart contract developers:
40+
41+
**It is <ins>highly</ins> discouraged to use try-catch patterns with unknown contracts in EVM environment**
42+
43+
Technically, this problem is similar to classic gas-griefing issues in EVM contracts, if not handled appropriately.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# EVM predeploys
2+
3+
Some important EVM contracts can be deployed to predefined addresses if EVM emulation is enabled on the chain. It can be done using [DeployEvmPredeploys.s.sol](../../l1-contracts/deploy-scripts/evm-predeploys/DeployEvmPredeploys.s.sol) script.
4+
5+
List of contracts:
6+
7+
- [Create2 proxy](https://github.com/Arachnid/deterministic-deployment-proxy)
8+
`0x4e59b44847b379578588920cA78FbF26c0B4956C`
9+
- [Create2 deployer](https://github.com/pcaversaccio/create2deployer)
10+
`0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2`
11+
- [ERC2470 singleton factory](https://eips.ethereum.org/EIPS/eip-2470)
12+
`0xce0042B868300000d44A59004Da54A005ffdcf9f`
13+
- [Safe Singleton Factory](https://github.com/safe-global/safe-singleton-factory/blob/main/source/deterministic-deployment-proxy.yul)
14+
`0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7`
15+
- [Multicall3](https://github.com/mds1/multicall/tree/main)
16+
`0xcA11bde05977b3631167028862bE2a173976CA11`
17+
- [Create2 proxy](https://github.com/Zoltu/deterministic-deployment-proxy)
18+
`0x7A0D94F55792C434d74a40883C6ed8545E406D12`

0 commit comments

Comments
 (0)