Skip to content

Commit 8c4d2ba

Browse files
committed
Additional fixes
1 parent 9103391 commit 8c4d2ba

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

program-analysis/echidna/basic/assertion-checking.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
## Introduction
1313

14-
In this short tutorial, we will demonstrate how to use Echidna to check assertions in smart contracts. For this example, be sure to use Solidity 0.7.x or older. If you run them with Solidity 0.8.x, the test will never fail.
14+
In this short tutorial, we will demonstrate how to use Echidna to check assertions in smart contracts.
1515

1616
## Write an Assertion
1717

@@ -23,7 +23,9 @@ contract Incrementor {
2323
2424
function inc(uint256 val) public returns (uint256) {
2525
uint256 tmp = counter;
26-
counter += val;
26+
unchecked {
27+
counter += val;
28+
}
2729
// tmp <= counter
2830
return (counter - tmp);
2931
}
@@ -38,7 +40,9 @@ contract Incrementor {
3840
3941
function inc(uint256 val) public returns (uint256) {
4042
uint256 tmp = counter;
41-
counter += val;
43+
unchecked {
44+
counter += val;
45+
}
4246
assert(tmp <= counter);
4347
return (counter - tmp);
4448
}
@@ -55,7 +59,9 @@ contract Incrementor {
5559
5660
function inc(uint256 val) public returns (uint256) {
5761
uint256 tmp = counter;
58-
counter += val;
62+
unchecked {
63+
counter += val;
64+
}
5965
if (tmp > counter) {
6066
emit AssertionFailed(counter);
6167
}

program-analysis/echidna/example/assert.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ contract Incrementor {
66

77
function inc(uint256 val) public returns (uint256) {
88
uint256 tmp = counter;
9-
counter += val;
9+
unchecked {
10+
counter += val;
11+
}
1012
assert(tmp <= counter);
1113
return (counter - tmp);
1214
}

program-analysis/echidna/exercises/exercise4/solution.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import "./token.sol";
99
/// echidna program-analysis/echidna/exercises/exercise4/solution.sol --contract TestToken --test-mode assertion
1010
/// ```
1111
contract TestToken is Token {
12-
function transfer(address to, uint256 value) override public {
12+
function transfer(address to, uint256 value) public override {
1313
uint256 oldBalanceFrom = balances[msg.sender];
1414
uint256 oldBalanceTo = balances[to];
1515

0 commit comments

Comments
 (0)