Skip to content

Commit 42d2a04

Browse files
Fix/fuzz tests improvements (#178)
* chore: fix linter setup * chore: update smocked files * chore: add missing spdx identifier * chore: add an npm script to run echidna tests * test: ensure SpotPriceAfterBelowSpotPriceBefore is never thrown * chore: fix natspec issues * test: ensure fuzz_joinExitPool body is runnable * chore: cleaning up fuzz (#179) * feat: creating BCoWPoolForTest to avoid modifying core contracts * fix: test:echidna script * fix: safeTransfer issue with echidna * chore: update test contract licenses * test: document property 25 * chore: remove unimplemented function --------- Co-authored-by: Weißer Hase <[email protected]>
1 parent 637aa83 commit 42d2a04

17 files changed

+129
-73
lines changed

Diff for: .forge-snapshots/newBFactory.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4130633
1+
4130621

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ broadcast/*/*/*
2121
out
2222

2323
# echidna corpuses
24-
**/corpuses/*
24+
**/corpuses/*
25+
**/crytic-export/*

Diff for: .solhintignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
test/smock/*
22
test/manual-smock/*
3-
test/invariants/*

Diff for: foundry.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sort_imports = true
1212
solc_version = '0.8.25'
1313
libs = ["node_modules", "lib"]
1414
optimizer_runs = 500
15-
evm_version = 'shanghai'
15+
evm_version = 'cancun'
1616
fs_permissions = [{ access = "read-write", path = ".forge-snapshots/"}]
1717
# 2018: function can be view, so far only caused by mocks
1818
# 2394: solc insists on reporting on every transient storage use

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"prepare": "husky install",
2828
"smock": "smock-foundry --contracts src/contracts",
2929
"test": "yarn test:integration && yarn test:unit",
30+
"test:echidna": "find test/invariants/fuzz -regex '.*\\.t\\.sol$' |cut -d '/' -f 4 | cut -d . -f 1 |xargs -I{} echidna test/invariants/fuzz/{}.t.sol --contract Fuzz{} --config test/invariants/fuzz/{}.yaml",
3031
"test:integration": "forge test --ffi --match-path 'test/integration/**' -vvv --isolate",
3132
"test:local": "FOUNDRY_FUZZ_RUNS=100 forge test -vvv",
3233
"test:scaffold": "bulloak check --fix test/unit/*.tree && forge fmt",

Diff for: src/contracts/BPool.sol

+7-13
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ contract BPool is BToken, BMath, IBPool {
3030
/// @dev Sum of all token weights
3131
uint256 internal _totalWeight;
3232

33-
/// TEST TEST TEST TEST TEST TEST TEST TEST
34-
bytes32 internal _reenteringMutex;
35-
/// TEST TEST TEST TEST TEST TEST TEST TEST
36-
3733
/// @dev Logs the call data
3834
modifier _logs_() {
3935
emit LOG_CALL(msg.sig, msg.sender, msg.data);
@@ -152,8 +148,8 @@ contract BPool is BToken, BMath, IBPool {
152148

153149
_pullUnderlying(token, msg.sender, balance);
154150
}
155-
/// @inheritdoc IBPool
156151

152+
/// @inheritdoc IBPool
157153
function unbind(address token) external _logs_ _lock_ _controller_ _notFinalized_ {
158154
if (!_records[token].bound) {
159155
revert BPool_TokenNotBound();
@@ -601,10 +597,9 @@ contract BPool is BToken, BMath, IBPool {
601597
* be interpreted as locked
602598
*/
603599
function _setLock(bytes32 value) internal virtual {
604-
// assembly ("memory-safe") {
605-
// tstore(_MUTEX_TRANSIENT_STORAGE_SLOT, value)
606-
// }
607-
_reenteringMutex = value;
600+
assembly ("memory-safe") {
601+
tstore(_MUTEX_TRANSIENT_STORAGE_SLOT, value)
602+
}
608603
}
609604

610605
/**
@@ -675,9 +670,8 @@ contract BPool is BToken, BMath, IBPool {
675670
* allowing calls
676671
*/
677672
function _getLock() internal view virtual returns (bytes32 value) {
678-
// assembly ("memory-safe") {
679-
// value := tload(_MUTEX_TRANSIENT_STORAGE_SLOT)
680-
// }
681-
value = _reenteringMutex;
673+
assembly ("memory-safe") {
674+
value := tload(_MUTEX_TRANSIENT_STORAGE_SLOT)
675+
}
682676
}
683677
}

Diff for: test/invariants/.solhint.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"rules": {
3+
"custom-errors": "off",
4+
"no-empty-blocks":"off",
5+
"reason-string": "off",
6+
"reentrancy": "off",
7+
"style-guide-casing": [ "warn", {
8+
"ignoreVariables": true,
9+
"ignorePublicFunctions": true,
10+
"ignoreExternalFunctions": true
11+
}]
12+
}
13+
}

Diff for: test/invariants/PROPERTIES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
| only the settler can commit a hash | High level | 22 | [x] | [x] |
2525
| when a hash has been commited, only this order can be settled | High level | 23 | [ ] | [ ] |
2626
| BToken should not break the ToB ERC20 properties** | High level | 24 | | [x] |
27+
| Spot price after swap is always greater than before swap | High level | 25 | | [x] |
2728

2829
> (*) Bundled with 24
2930
@@ -88,4 +89,4 @@ power of a power should mult the exp (x^a)^b == x^(a*b)
8889
## Untested (precision issues in test settingsq)
8990
calcOutGivenIn should be inv with calcInGivenOut
9091
calcPoolOutGivenSingleIn should be inv with calcSingleInGivenPoolOut
91-
calcSingleOutGivenPoolIn should be inv with calcPoolInGivenSingleOut
92+
calcSingleOutGivenPoolIn should be inv with calcPoolInGivenSingleOut

Diff for: test/invariants/fuzz/BNum.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-License-Identifier: UNLICENSED
1+
// SPDX-License-Identifier: MIT
22
pragma solidity 0.8.25;
33

44
import {EchidnaTest} from '../helpers/AdvancedTestsUtils.sol';

Diff for: test/invariants/fuzz/BToken.t.sol

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
// SPDX-License-Identifier: MIT
12
pragma solidity 0.8.25;
23

34
import {EchidnaTest} from '../helpers/AdvancedTestsUtils.sol';
45
import {CryticERC20ExternalBasicProperties} from
56
'@crytic/properties/contracts/ERC20/external/properties/ERC20ExternalBasicProperties.sol';
67
import {ITokenMock} from '@crytic/properties/contracts/ERC20/external/util/ITokenMock.sol';
78
import {PropertiesConstants} from '@crytic/properties/contracts/util/PropertiesConstants.sol';
8-
import 'contracts/BToken.sol';
9+
import {BToken} from 'contracts/BToken.sol';
910

1011
contract FuzzBToken is CryticERC20ExternalBasicProperties, EchidnaTest {
1112
constructor() {

0 commit comments

Comments
 (0)