Skip to content

Commit 125572e

Browse files
authored
Merge pull request #342 from reytchison/reytchison-patch
Update Echidna exercise pages and small fixes
2 parents eb6ea12 + 293b900 commit 125572e

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

program-analysis/echidna/advanced/smart-contract-fuzzing-at-scale.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Once it runs, check the coverage file located in `corpus-exploration/covered.*.t
7474

7575
## 3. Initiate a continuous fuzzing campaign
7676

77-
When satisfied with the first iteration of the initialization, we can start a "continuous campaign" for exploration and testing using [echidna-parade](https://github.com/agroce/echidna-parade). Before starting, double-check your config file. For instance, if you added properties, do not forget to remove `benchmarkMode`.
77+
When satisfied with the first iteration of the initialization, we can start a "continuous campaign" for exploration and testing using [echidna-parade](https://github.com/crytic/echidna-parade). Before starting, double-check your config file. For instance, if you added properties, do not forget to remove `benchmarkMode`.
7878

7979
`echidna-parade` is a tool used to launch multiple Echidna instances simultaneously while keeping track of each corpus. Each instance will be configured to run for a specific duration, with different parameters, to maximize the chance of reaching new code.
8080

program-analysis/echidna/basic/working-with-eth.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,4 @@ echidna_C_has_some_value: failed!💥
116116
Echidna has two options for using ether during a fuzzing campaign.
117117

118118
- `maxValue` to set the max amount of ether per transaction
119-
- `contractBalance` to set the initial amount of ether that the testing contract receives in the constructor.
119+
- `balanceContract` to set the initial amount of ether that the testing contract receives in the constructor.

program-analysis/echidna/exercises/Exercise-1.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ contract Token is Ownable, Pausable {
5151
mapping(address => uint256) public balances;
5252
5353
function transfer(address to, uint256 value) public whenNotPaused {
54-
balances[msg.sender] -= value;
55-
balances[to] += value;
54+
// unchecked to save gas
55+
unchecked {
56+
balances[msg.sender] -= value;
57+
balances[to] += value;
58+
}
5659
}
5760
}
5861
```
@@ -79,8 +82,8 @@ import "./token.sol";
7982
contract TestToken is Token {
8083
address echidna = tx.origin;
8184
82-
constructor() public {
83-
balances[echidna] = 10000;
85+
constructor() {
86+
balances[echidna] = 10_000;
8487
}
8588
8689
function echidna_test_balance() public view returns (bool) {

program-analysis/echidna/exercises/Exercise-2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import "./token.sol";
8484
/// echidna program-analysis/echidna/exercises/exercise2/template.sol
8585
/// ```
8686
contract TestToken is Token {
87-
constructor() public {
87+
constructor() {
8888
pause(); // pause the contract
8989
owner = address(0); // lose ownership
9090
}

program-analysis/echidna/exercises/Exercise-3.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ We will test the following contract _[token.sol](https://github.com/crytic/build
1919
```solidity
2020
pragma solidity ^0.8.0;
2121
22-
/// @notice The issues from exercises 1 and 2 are fixed.
22+
/// @notice The issues from exercise 1 and 2 are fixed.
2323
2424
contract Ownable {
2525
address public owner = msg.sender;
@@ -74,7 +74,7 @@ contract MintableToken is Token {
7474
int256 public totalMinted;
7575
int256 public totalMintable;
7676
77-
constructor(int256 totalMintable_) public {
77+
constructor(int256 totalMintable_) {
7878
totalMintable = totalMintable_;
7979
}
8080
@@ -111,7 +111,7 @@ contract TestToken is MintableToken {
111111
address echidna = msg.sender;
112112
113113
// TODO: update the constructor
114-
constructor(int256 totalMintable) public MintableToken(totalMintable) {}
114+
constructor(int256 totalMintable) MintableToken(totalMintable) {}
115115
116116
function echidna_test_balance() public view returns (bool) {
117117
// TODO: add the property

program-analysis/echidna/exercises/Exercise-4.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ contract Ownable {
2727
}
2828
2929
modifier onlyOwner() {
30-
require(msg.sender == owner, "Ownable: Caller is not the owner");
30+
require(msg.sender == owner, "Ownable: Caller is not the owner.");
3131
_;
3232
}
3333
}
@@ -48,17 +48,20 @@ contract Pausable is Ownable {
4848
}
4949
5050
modifier whenNotPaused() {
51-
require(!_paused, "Pausable: Contract is paused");
51+
require(!_paused, "Pausable: Contract is paused.");
5252
_;
5353
}
5454
}
5555
5656
contract Token is Ownable, Pausable {
5757
mapping(address => uint256) public balances;
5858
59-
function transfer(address to, uint256 value) public whenNotPaused {
60-
balances[msg.sender] -= value;
61-
balances[to] += value;
59+
function transfer(address to, uint256 value) public virtual whenNotPaused {
60+
// unchecked to save gas
61+
unchecked {
62+
balances[msg.sender] -= value;
63+
balances[to] += value;
64+
}
6265
}
6366
}
6467
```
@@ -88,6 +91,10 @@ import "./token.sol";
8891
/// solc-select use 0.8.0
8992
/// echidna program-analysis/echidna/exercises/exercise4/template.sol --contract TestToken --test-mode assertion
9093
/// ```
94+
/// or by providing a config
95+
/// ```
96+
/// echidna program-analysis/echidna/exercises/exercise4/template.sol --contract TestToken --config program-analysis/echidna/exercises/exercise4/config.yaml
97+
/// ```
9198
contract TestToken is Token {
9299
function transfer(address to, uint256 value) public {
93100
// TODO: include `assert(condition)` statements that

0 commit comments

Comments
 (0)