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-6Lines changed: 9 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,18 +6,17 @@
6
6
-[Example code](#example-code)
7
7
-[Deploying libraries](#deploying-libraries)
8
8
-[Linking libraries](#linking-libraries)
9
+
-[Summary](#summary)
9
10
10
11
## Introduction
11
12
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
13
+
Solidity introduced a the concept of a smart contract library. 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
16
- If all the functions are internal, the library is compiled into bytecode and added into the contracts that use it.
17
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
-
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
-
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.
19
+
The following is only needed if your codebase uses libraries that need to be linked. 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.
21
20
22
21
## Example code
23
22
@@ -50,7 +49,7 @@ to pass to `crytic-compile` from Echidna:
Going back to the example, if we have both config options in a single config file (`echidna.yaml), we can run the metacoin contract
52
+
Going back to the example, if we have both config options in a single config file (`echidna.yaml`), we can run the metacoin contract
54
53
in `exploration` mode:
55
54
56
55
```
@@ -65,7 +64,7 @@ We can use the coverage report to verify that function using the library (`getBa
65
64
30 | | }
66
65
```
67
66
68
-
However, the code of library itself will not have their coverage displayed correctly:
67
+
However, the code of the library itself will not have their coverage displayed correctly:
69
68
70
69
```
71
70
6 | | library ConvertLib{
@@ -77,3 +76,7 @@ However, the code of library itself will not have their coverage displayed corre
77
76
```
78
77
79
78
This is caused by the usage of `delegatecall` to execute contract code and unfortunately we do not have a workaround for it right now.
79
+
80
+
## Summary
81
+
82
+
Working with libraries in Echidna is supported. It involves to deploy the library to a particular address using `deployContracts` and then asking `crytic-compile` to link the bytecode with the same address using `--compile-libraries` command line.
0 commit comments