Skip to content

Commit 367e8d5

Browse files
Add documentation of the EVM support in Linera. (#228)
Add the first version of the documentation of EVM support in Linera.
1 parent 55bcdde commit 367e8d5

File tree

3 files changed

+106
-2
lines changed

3 files changed

+106
-2
lines changed

src/appendix/glossary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
selected at the next block height.
2323

2424
- **Bytecode**: A collection of bytes corresponding to a program that can be run
25-
by the Wasm virtual machine.
25+
by the virtual machine. This is either a Wasm or EVM bytecode.
2626

2727
- **Client**: The `linera` program, which is a local node and wallet operated by
2828
users to make requests to the network. In Linera, clients drive the network by

src/developers/advanced_topics/block_creation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ several types of chains, depending on how new blocks are produced.
1818
Instead, the wallets (aka. `linera` clients) of chain owners make the system
1919
progress by proposing blocks and actively providing any additional required data
2020
to the validators. For instance, client commands such as `transfer`,
21-
`publish-bytecode`, or `open-chain` perform multiple steps to append a block
21+
`publish-module`, or `open-chain` perform multiple steps to append a block
2222
containing the token transfer, application publishing, or chain creation
2323
operation:
2424

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Using EVM-Based Smart Contracts on Linera
2+
3+
It is possible to use Ethereum Virtual Machine (EVM)-based smart contracts on
4+
Linera. These contracts are typically written in Solidity.
5+
6+
EVM smart contracts have access Linera-specific functionality of Linera through
7+
the `Linera.sol` library which exposes necessary interfaces for integration.
8+
9+
This allows smart contracts originally deployed on Ethereum to be migrated to
10+
Linera and progressively adapted to Linera’s architecture and features.
11+
12+
## Publishing EVM Smart Contracts
13+
14+
The process for publishing EVM smart contracts is similar to that for Wasm smart
15+
contracts, with the key difference being the need to specify the virtual machine
16+
used (the default is Wasm).
17+
18+
For EVM contracts, there is only one bytecode file (unlike Wasm, which requires
19+
separate `contract` and `service` binaries). Therefore, the same file must be
20+
passed twice:
21+
22+
```bash
23+
linera publish-and-create \
24+
counter.bytecode counter.bytecode \
25+
--vm-runtime evm \
26+
--json-parameters "42"
27+
```
28+
29+
Here, `counter.bytecode` contains the compiled contract, and "42" is passed as a
30+
constructor argument via the `--json-parameters` flag.
31+
32+
Constructor arguments for the EVM contract are passed through application
33+
parameters. Instantiation-specific arguments are provided separately.
34+
35+
## Calling other smart contracts.
36+
37+
EVM smart contracts on Linera can invoke other EVM contracts using standard
38+
Solidity syntax.
39+
40+
### EVM Contracts calling Wasm smart contracts.
41+
42+
To call a Wasm smart contract from an EVM contract, use the following Solidity
43+
command:
44+
45+
```solidity
46+
bytes memory return_value = Linera.try_call_application(address, input);
47+
```
48+
49+
- `address`: the address of the Wasm smart contract, as a `bytes32`.
50+
- `input`: the bytes representing the BCS-serialized `ContractAbi::Operation`
51+
input.
52+
53+
The serialization code can be generated using the `serde-reflection` crate.
54+
55+
### Wasm Smart Contracts calling EVM Contracts.
56+
57+
Wasm smart contracts can call EVM contracts using the `alloy-sol-types` crate.
58+
This crate enables construction of Solidity-compatible types and supports RLP
59+
serialization/deserialization.
60+
61+
The Wasm contract call-evm-counter demonstrates this functionality.
62+
63+
- For operations, the input type is `Vec<u8>`.
64+
65+
- For service calls, the input type is `EvmQuery`.
66+
67+
Note: Linera distinguishes between contract and service code execution contexts.
68+
69+
## Multichain EVM applications.
70+
71+
To operate across multiple chains, an EVM application must implement the
72+
following functions:
73+
74+
```solidity
75+
function instantiate(bytes memory input) external
76+
function execute_message(bytes memory input) external
77+
```
78+
79+
- `instantiate` is called on the creator chain.
80+
81+
- `execute_message` handles incoming cross-chain messages.
82+
83+
Additional SDK functions available include:
84+
85+
```solidity
86+
Linera.chain_ownership()
87+
Linera.read_data_blob()
88+
Linera.assert_data_blob_exists()
89+
Linera.validation_round()
90+
Linera.message_id()
91+
Linera.message_is_bouncing()
92+
```
93+
94+
## Difference between EVM applications in Ethereum and Linera.
95+
96+
- `Reentrancy`: Reentrancy is not supported on Linera. Contracts relying on it
97+
will fail with a clean error.
98+
99+
- `Address Computation`: Contract addresses are computed differently from
100+
Ethereum.
101+
102+
- `Gas Limits`: Following Infura's practice, Linera imposes a gas limit of
103+
20,000,000 for service calls in EVM contracts. Contract execution is similarly
104+
constrained.

0 commit comments

Comments
 (0)