You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: program-analysis/echidna/advanced/working-with-libraries.md
+9-13Lines changed: 9 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,12 +9,12 @@
9
9
10
10
## Introduction
11
11
12
-
One important feature used Solidity introduced a brand new concept of smart contract library. While this feature is not extremely popular, a good amount of contracts use them to structure code and reduce the amount of bytecode deployed.
13
-
Before continue, it is very recommended to review [the official Solidity documentation](https://docs.soliditylang.org/en/v0.8.19/contracts.html#libraries) to make sure
12
+
One important feature used Solidity introduced a brand new concept of smart contract library. While this feature is not extremely popular, a good amount of contracts use them to structure code and reduce the amount of bytecode deployed.
13
+
Before continue, it is very recommended to review [the official Solidity documentation](https://docs.soliditylang.org/en/v0.8.19/contracts.html#libraries) to make sure
14
14
you understand how libraries are created and deployed. When a user creates a library, Solidity will do one of these two options:
15
15
16
-
* If all the functions are internal, the library is compiled into bytecode and added into the contracts that use it.
17
-
* If there are some external functions, the library should be deployed into some address. Finally, the bytecode calling the library should be linked.
16
+
- If all the functions are internal, the library is compiled into bytecode and added into the contracts that use it.
17
+
- If there are some external functions, the library should be deployed into some address. Finally, the bytecode calling the library should be linked.
18
18
19
19
If your libraries only contain internal functions, then Echidna will work correctly and you don't need to do anything extra to start your testing (you can skip the rest of the tutorial).
20
20
However, if you need to use libraries that needed to be deployed (and the bytecode needs to be linked), then you will need this tutorial.
@@ -34,24 +34,20 @@ $ npm i
34
34
Libraries are contracts that need to be deployed first. Fortunately, Echidna allows us to do that easily, using the `deployContracts` option. In the metacoin example, we can use:
35
35
36
36
```yaml
37
-
deployContracts: [
38
-
["0x1f", "ConvertLib"],
39
-
]
37
+
deployContracts: [["0x1f", "ConvertLib"]]
40
38
```
41
39
42
40
The address where the library should be deployed is arbitrary, but it should be the same as the one in the used during the linking process.
43
41
44
42
## Linking libraries
45
43
46
-
Before a contract can use a deployed library, its bytecode requires to be linked. This procedure requries to replace a particular string place holder
44
+
Before a contract can use a deployed library, its bytecode requires to be linked. This procedure requries to replace a particular string place holder
47
45
in the bytecode by the address of the deployed library. Normally, either solc or the compilation framework (e.g. truffle) will take care of this.
48
-
However, in our case, we will use `crytic-compile`, since it is easier to handle all cases from different frameworks just adding one new argument
46
+
However, in our case, we will use `crytic-compile`, since it is easier to handle all cases from different frameworks just adding one new argument
0 commit comments