Skip to content

Commit c72df6c

Browse files
hedgar2017popzxc
andauthored
fix: replace the EraVM extension page with zksolc docs (#296)
<!-- Thank you for contributing to the ZKsync Docs! Before submitting the PR, please make sure you do the following: - Update your PR title to follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) - Read the [Contributing Guide](https://github.com/matter-labs/zksync-docs/blob/main/CONTRIBUTING.md). - Understand our [Code of Conduct](https://github.com/matter-labs/zksync-docs/blob/main/CODE_OF_CONDUCT.md) - Please delete any unused parts of the template when submitting your PR --> # Description Replaces the EraVM extension page with links to zksolc docs. Fixes #269 Co-authored-by: Igor Aleksanov <[email protected]>
1 parent 0633029 commit c72df6c

File tree

13 files changed

+36
-430
lines changed

13 files changed

+36
-430
lines changed

content/00.zksync-era/40.tooling/20.hardhat/30.plugins/40.hardhat-zksync-solc.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,9 @@ This approach is implemented to provide a caching mechanism, avoiding the risk o
157157

158158
### ZKsync Era Solidity compiler
159159

160-
Due to [the identified limitations](/zksync-protocol/compiler/toolchain/solidity#limitations)
161-
of the [upstream Solidity compiler](https://github.com/ethereum/solidity),
162-
our team has developed [a new edition](%%zk_git_repo_era-solidity%%)
163-
of the compiler, which effectively addresses and resolves these constraints.
160+
Due to [several codegen limitations](/zksync-protocol/compiler/specification/evmla-translator)
161+
of the [upstream Solidity compiler](https://github.com/ethereum/solidity), our team
162+
had to [fork it](%%zk_git_repo_era-solidity%%) in order to effectively address and resolve these constraints.
164163

165164
For usage of EraVM compiler, `eraVersion` should be added inside `solidity` property in the `hardhat.config.ts` file:
166165

content/20.zksync-protocol/50.compiler/10.toolchain/10.index.md

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@ title: Compiler toolchain overview
33
description:
44
---
55

6-
This section introduces the zkEVM LLVM-based compiler toolchain for smart contract languages with Ethereum Virtual Machine (EVM) support.
6+
This section introduces an LLVM-based compiler toolchain for Solidity and Vyper.
77
The toolchain works on top of existing compilers and requires their output, which typically includes intermediate representations (IRs),
88
abstract syntax trees (ASTs), and auxiliary contract metadata and documentation.
99

10-
::callout{icon="i-heroicons-information-circle" color="blue"}
11-
At the time of writing, we support Solidity and Vyper.
12-
::
13-
1410
The toolchain consists of the following:
1511

1612
1. [High-level source code compilers](#high-level-source-code-compilers): `solc` and `vyper`.
1713
2. [IR compilers, front ends to LLVM](#ir-compilers): `zksolc` and `zkvyper`.
18-
3. [The LLVM framework](/zksync-protocol/compiler/toolchain/llvm) with a zkEVM back end which emits zkEVM text assembly.
19-
4. [The assembler](#assembler) which produces the zkEVM bytecode from text assembly.
20-
5. [Hardhat plugins](#hardhat-plugins) which set up the environment.
14+
3. [The LLVM framework](/zksync-protocol/compiler/toolchain/llvm) with EraVM and EVM back ends.
2115

2216
![Compiler Toolchain Visualization](/images/zk-stack/compiler-toolchain.png "Compiler Toolchain")
2317

@@ -26,10 +20,10 @@ The toolchain consists of the following:
2620
High-level source code is processed by third-party compilers. These compilers do the following:
2721

2822
1. Process and validate the high-level source code.
29-
2. Translate the source code into IR and metadata.
30-
3. Pass the IR and metadata to our IR compilers via the standard I/O streams.
23+
2. Translate the source code to artifacts, namely IR and metadata.
24+
3. Pass the IR and metadata to our IR compilers via stdout using standard JSON I/O.
3125

32-
We are using two high-level source code compilers at the time of writing:
26+
We are using two high-level source code compilers:
3327

3428
- [solc](https://github.com/ethereum/solc-bin): the official Solidity compiler. For more info, see the latest [Solidity documentation](https://docs.soliditylang.org/en/latest/).
3529
- [vyper](https://github.com/vyperlang/vyper/releases): the official Vyper compiler. For more info, see the latest [Vyper documentation](https://docs.vyperlang.org/en/latest/index.html).
@@ -43,43 +37,21 @@ to build smart contracts on ZKsync Era.
4337

4438
## IR Compilers
4539

46-
Our toolchain includes LLVM front ends, written in Rust, that process the output of high-level source code compilers:
40+
Our toolchain includes LLVM front ends written in Rust. The front ends process the output of high-level source code compilers:
4741

48-
- [zksolc](%%zk_git_repo_zksolc-bin%%) which calls `solc` as a child process. For more info, see the latest [zksolc documentation](/zksync-protocol/compiler/toolchain/solidity).
49-
- [zkvyper](%%zk_git_repo_zkvyper-bin%%): which calls `vyper` as a child process. For more info, see the latest [zkvyper documentation](/zksync-protocol/compiler/toolchain/vyper).
42+
- [zksolc](%%zk_git_repo_zksolc-bin%%) which calls `solc` as a child process. For more info, see the latest [zksolc documentation](https://matter-labs.github.io/era-compiler-solidity/latest/).
43+
- [zkvyper](%%zk_git_repo_zkvyper-bin%%): which calls `vyper` as a child process. For more info, see the latest [zkvyper documentation](https://matter-labs.github.io/era-compiler-vyper/latest/).
5044

5145
These IR compilers perform the following steps:
5246

53-
1. Receive the input, which is usually standard or combined JSON passed by the Hardhat plugin via standard input.
54-
2. Save the relevant data, modify the input with zkEVM settings, and pass it to the underlying high-level source code compiler
55-
which is called as a child process.
47+
1. Receive the input, which is usually standard or combined JSON passed by a tool such as Foundry or Hardhat via standard input.
48+
2. Save the relevant data, modify the input, and pass it to the underlying high-level source code compiler
49+
called as a child process.
5650
3. Receive the IR and metadata from the underlying compiler.
5751
4. Translate the IR into LLVM IR, resolving dependencies with the help of metadata.
58-
5. Optimize the LLVM IR with the powerful LLVM framework optimizer and emit zkEVM text assembly.
52+
5. Optimize the LLVM IR with the powerful LLVM framework optimizer and emit bytecode.
5953
6. Print the output matching the format of the input method the IR compiler is called with.
6054

6155
Our IR compilers leverage I/O mechanisms which already exist in the high-level source code
62-
compilers. They may modify the input and output to some extent, add data for features unique to zkEVM,
56+
compilers. They may modify the input and output to some extent, add data for features unique to ZKsync EraVM,
6357
and remove unsupported feature artifacts.
64-
65-
## Assembler
66-
67-
The [assembler](%%zk_git_repo_era-zkEVM-assembly%%), which is written in Rust, compiles zkEVM assembly
68-
to zkEVM bytecode. This tool is not a part of our LLVM back end as it uses several cryptographic libraries which are
69-
easier to maintain outside of the framework.
70-
71-
## Hardhat Plugins
72-
73-
We recommend using our IR compilers via [their corresponding Hardhat plugins](/zksync-era/tooling/hardhat).
74-
Add these plugins to the Hardhat's config file to compile new projects or migrate
75-
existing ones to ZKsync Era. For a lower-level approach, download our compiler binaries via the
76-
links above and use their CLI interfaces.
77-
78-
### Installing and configuring plugins
79-
80-
Add the plugins below to the Hardhat's config file to compile new projects or migrate
81-
existing ones to ZKsync Era. For a lower-level approach, download our compiler binaries
82-
[links above](#ir-compilers) and use their CLI interfaces.
83-
84-
- [hardhat-zksync-solc documentation](/zksync-era/tooling/hardhat/plugins/hardhat-zksync-solc)
85-
- [hardhat-zksync-vyper documentation](/zksync-era/tooling/hardhat/plugins/hardhat-zksync-vyper)
File renamed without changes.

content/20.zksync-protocol/50.compiler/10.toolchain/20.solidity.md

Lines changed: 0 additions & 121 deletions
This file was deleted.

content/20.zksync-protocol/50.compiler/10.toolchain/30.vyper.md

Lines changed: 0 additions & 49 deletions
This file was deleted.

content/20.zksync-protocol/50.compiler/20.specification/30.system-contracts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ For reference, see
116116

117117
## Auxiliary Heap
118118

119-
Both [zksolc](/zksync-protocol/compiler/toolchain/solidity) and [zkvyper](/zksync-protocol/compiler/toolchain/vyper)
119+
Both [zksolc](https://matter-labs.github.io/era-compiler-solidity/latest/) and [zkvyper](https://matter-labs.github.io/era-compiler-vyper/latest/)
120120
compilers for EraVM operate on [the IR level](/zksync-protocol/compiler/toolchain#ir-compilers),
121121
so they cannot control the heap memory allocator which remains a responsibility of
122122
[the high-level source code compilers](/zksync-protocol/compiler/toolchain#high-level-source-code-compilers) emitting the IRs.

content/20.zksync-protocol/50.compiler/20.specification/50.evmla-translator.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,29 @@ title: EVM Legacy Assembly translator
33
description:
44
---
55

6-
There are two Solidity IRs used in our pipeline: Yul and EVM legacy assembly. The former is used for older versions of
6+
There are two Solidity IRs used in our pipeline: Yul and EVM legacy assembly. The latter is used for older versions of
77
Solidity, more precisely <=0.7.
88

99
EVM legacy assembly is very challenging to translate to LLVM IR, since it obfuscates the control flow of the program and
10-
uses a lot of dynamic jumps. Most of the jumps can be translated to static ones by using a static analysis of EVM assembly,
11-
but some of jumps are impossible to resolve statically. For example, internal function pointers can be written
12-
to memory or storage, and then loaded and called. Recursion is another case we have skipped for now, as there is another
13-
stack frame allocated on every iteration, preventing the static analyzer from resolving the jumps.
10+
uses a lot of dynamic jumps. Most of the jumps can be translated to static ones by using a form of static analysis,
11+
but some of them are impossible to resolve this way.
1412

15-
Both issues are being worked on in our fork of the Solidity compiler, where we are changing the codegen to remove the
16-
dynamic jumps and add the necessary metadata.
13+
## ZKsync Fork of the Solidity Compiler
1714

18-
Below you can see a minimal example of a Solidity contract and its EVM legacy assembly translated to LLVM IR which is
19-
eventually compiled to EraVM assembly.
15+
There were several issues with the existing codegen of the original *solc* compiler:
16+
17+
1. Internal function pointers are written to memory or storage, and then loaded and called dynamically.
18+
2. With local recursion, there is another stack frame allocated on every iteration.
19+
3. Some try-catch patterns leave values on the stack, hindering stack analysis.
20+
21+
All the issues have been resolved in [our fork of the Solidity compiler](https://github.com/matter-labs/era-solidity),
22+
where we have changed the codegen to remove the dynamic jumps and add the necessary metadata.
2023

2124
## Source Code
2225

26+
In this section you can see a minimal example of a Solidity contract and its EVM legacy assembly translated to LLVM IR which is
27+
eventually compiled to EraVM bytecode.
28+
2329
```solidity
2430
contract Example {
2531
function main() public pure returns (uint256 result) {

content/20.zksync-protocol/50.compiler/20.specification/60.instructions/10.index.md

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ stated explicitly in the description of each instruction.
1515
## Addressing modes
1616

1717
EraVM is a register-based virtual machine with different addressing modes.
18-
It overrides all stack mechanics described in [the original EVM opcodes documentation](https://www.evm.codes/) including
18+
It overrides all stack mechanics described in [the official documentation of EVM opcodes](https://www.evm.codes/) including
1919
errors they produce on EVM.
2020

2121
## Solidity Intermediate Representations (IRs)
@@ -27,22 +27,4 @@ Every instruction is translated via two IRs available in the Solidity compiler u
2727

2828
## Yul Extensions
2929

30-
At the moment there is no way of adding ZKsync-specific instructions to Yul as long as we use the official Solidity
31-
compiler, which would produce an error on an unknown instruction.
32-
33-
There are two ways of supporting such instructions: one for Solidity and one for Yul.
34-
35-
### The Solidity Mode
36-
37-
In Solidity we have introduced **call simulations**. They are not actual calls, as they are substituted by our Yul
38-
translator with the needed instruction, depending on the constant address. This way the Solidity compiler is not
39-
optimizing them out and is not emitting compilation errors.
40-
41-
The reference of such extensions is coming soon.
42-
43-
### The Yul Mode
44-
45-
The non-call ZKsync-specific instructions are only available in the Yul mode of **zksolc**.
46-
To have better compatibility, they are implemented as `verbatim` instructions with some predefined keys.
47-
48-
The reference of such extensions is coming soon.
30+
ZKsync EraVM introduced a set of EraVM-specific instructions. The set is documented at [the official *zksolc* documentation](https://matter-labs.github.io/era-compiler-solidity/latest/).

content/20.zksync-protocol/50.compiler/20.specification/60.instructions/21.extensions/00.index.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)