Skip to content

Commit 7a9c8ca

Browse files
run format
1 parent 19c4152 commit 7a9c8ca

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

program-analysis/echidna/advanced/working-with-libraries.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
## Introduction
1111

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
1414
you understand how libraries are created and deployed. When a user creates a library, Solidity will do one of these two options:
1515

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.
1818

1919
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).
2020
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
3434
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:
3535

3636
```yaml
37-
deployContracts: [
38-
["0x1f", "ConvertLib"],
39-
]
37+
deployContracts: [["0x1f", "ConvertLib"]]
4038
```
4139
4240
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.
4341
4442
## Linking libraries
4543
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
4745
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
4947
to pass to `crytic-compile` from Echidna:
5048

5149
```yaml
52-
cryticArgs: [
53-
"--compile-libraries=(ConvertLib,0x1f)",
54-
]
50+
cryticArgs: ["--compile-libraries=(ConvertLib,0x1f)"]
5551
```
5652

5753
Going back to the example, if we have both config options in a single config file (`echidna.yaml), we can run the metacoin contract
@@ -71,7 +67,7 @@ We can use the coverage report to verify that function using the library (`getBa
7167

7268
However, the code of library itself will not have their coverage displayed correctly:
7369

74-
```
70+
```
7571
6 | | library ConvertLib{
7672
7 | | function convert(uint amount, uint conversionRate) public pure returns (uint convertedAmount)
7773
8 | | {

0 commit comments

Comments
 (0)