Skip to content

Commit 2f800bc

Browse files
committed
chaincheck: Adds config flag to disable check, fix bug
1 parent 1361fb4 commit 2f800bc

File tree

2 files changed

+63
-43
lines changed

2 files changed

+63
-43
lines changed

Diff for: script/IAuthChaincheck.sol

+31-21
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import {IAuth} from "src/auth/IAuth.sol";
1313
* @notice IAuth's `chaincheck` Integration Test
1414
*
1515
* @dev Config Definition:
16+
*
1617
* ```json
1718
* {
1819
* "IAuth": {
20+
* "disabled": bool,
1921
* "legacy": bool,
2022
* "authed": [
2123
* "<Ethereum address>",
@@ -31,23 +33,23 @@ contract IAuthChaincheck is Chaincheck {
3133
Vm internal constant vm =
3234
Vm(address(uint160(uint(keccak256("hevm cheat code")))));
3335

34-
IAuth private auth;
35-
string private config;
36+
IAuth self;
37+
string config;
3638

37-
string[] private _logs;
39+
string[] logs;
3840

3941
modifier notLegacy() {
4042
if (!config.readBool(".IAuth.legacy")) {
4143
_;
4244
}
4345
}
4446

45-
function setUp(address self, string memory config_)
47+
function setUp(address self_, string memory config_)
4648
external
4749
override(Chaincheck)
4850
returns (Chaincheck)
4951
{
50-
auth = IAuth(self);
52+
self = IAuth(self_);
5153
config = config_;
5254

5355
return Chaincheck(address(this));
@@ -58,13 +60,18 @@ contract IAuthChaincheck is Chaincheck {
5860
override(Chaincheck)
5961
returns (bool, string[] memory)
6062
{
63+
// Don't run if disabled.
64+
if (config.readBool(".IAuth.disabled")) {
65+
return (logs.length == 0, logs);
66+
}
67+
6168
check_authed_containsAllExpectedAddresses();
6269
check_authed_onlyExpectedAddressesAreAuthed();
6370
check_authed_zeroAddressNotAuthed();
6471
check_authed_ownAddressNotAuthed();
6572

6673
// Fail run if non-zero number of logs.
67-
return (_logs.length == 0, _logs);
74+
return (logs.length == 0, logs);
6875
}
6976

7077
/// @dev Checks that each address expected to be auth'ed is actually
@@ -75,8 +82,8 @@ contract IAuthChaincheck is Chaincheck {
7582
// Check that each expected address is auth'ed.
7683
for (uint i; i < expected.length; i++) {
7784
// Using `wards(address)(uint)` to support legacy instances.
78-
if (auth.wards(expected[i]) != 1) {
79-
_logs.push(
85+
if (self.wards(expected[i]) != 1) {
86+
logs.push(
8087
string.concat(
8188
StdStyle.red("Expected address not auth'ed: "),
8289
vm.toString(expected[i])
@@ -91,40 +98,43 @@ contract IAuthChaincheck is Chaincheck {
9198
/// @dev Only non-legacy versions supported.
9299
function check_authed_onlyExpectedAddressesAreAuthed() internal notLegacy {
93100
address[] memory expected = config.readAddressArray(".IAuth.authed");
94-
address[] memory actual = auth.authed();
101+
address[] memory actual = self.authed();
95102

96103
for (uint i; i < actual.length; i++) {
104+
bool found = false;
105+
97106
for (uint j; j < expected.length; j++) {
98107
if (actual[i] == expected[j]) {
108+
found = true;
99109
break; // Found address. Continue with outer loop.
100110
}
111+
}
101112

113+
if (!found) {
102114
// Log if unknown address auth'ed.
103-
if (j == expected.length - 1) {
104-
_logs.push(
105-
string.concat(
106-
StdStyle.red("Unknown address auth'ed: "),
107-
vm.toString(actual[i])
108-
)
109-
);
110-
}
115+
logs.push(
116+
string.concat(
117+
StdStyle.red("Unknown address auth'ed: "),
118+
vm.toString(actual[i])
119+
)
120+
);
111121
}
112122
}
113123
}
114124

115125
/// @dev Checks that the zero address is not auth'ed.
116126
function check_authed_zeroAddressNotAuthed() internal {
117127
// Using `wards(address)(uint)` to support legacy instances.
118-
if (auth.wards(address(0)) != 0) {
119-
_logs.push(StdStyle.red("Zero address auth'ed"));
128+
if (self.wards(address(0)) != 0) {
129+
logs.push(StdStyle.red("Zero address auth'ed"));
120130
}
121131
}
122132

123133
/// @dev Checks that own address is not auth'ed.
124134
function check_authed_ownAddressNotAuthed() internal {
125135
// Using `wards(address)(uint)` to support legacy instances.
126-
if (auth.wards(address(auth)) != 0) {
127-
_logs.push(StdStyle.red("Own address auth'ed"));
136+
if (self.wards(address(self)) != 0) {
137+
logs.push(StdStyle.red("Own address auth'ed"));
128138
}
129139
}
130140
}

Diff for: script/ITollChaincheck.sol

+32-22
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import {IToll} from "src/toll/IToll.sol";
1414
* @notice IToll's `chaincheck` Integration Test
1515
*
1616
* @dev Config Definition:
17+
*
1718
* ```json
1819
* {
1920
* "IToll": {
21+
* "disabled": bool,
2022
* "legacy": bool,
2123
* "tolled": [
2224
* "<Ethereum address>",
@@ -32,23 +34,23 @@ contract ITollChaincheck is Chaincheck {
3234
Vm internal constant vm =
3335
Vm(address(uint160(uint(keccak256("hevm cheat code")))));
3436

35-
IToll private toll;
36-
string private config;
37+
IToll self;
38+
string config;
3739

38-
string[] private _logs;
40+
string[] logs;
3941

4042
modifier notLegacy() {
4143
if (!config.readBool(".IToll.legacy")) {
4244
_;
4345
}
4446
}
4547

46-
function setUp(address self, string memory config_)
48+
function setUp(address self_, string memory config_)
4749
external
4850
override(Chaincheck)
4951
returns (Chaincheck)
5052
{
51-
toll = IToll(self);
53+
self = IToll(self_);
5254
config = config_;
5355

5456
return Chaincheck(address(this));
@@ -59,13 +61,18 @@ contract ITollChaincheck is Chaincheck {
5961
override(Chaincheck)
6062
returns (bool, string[] memory)
6163
{
64+
// Don't run if disabled.
65+
if (config.readBool(".IToll.disabled")) {
66+
return (logs.length == 0, logs);
67+
}
68+
6269
check_tolled_containsAllExpectedAddresses();
6370
check_tolled_onlyExpectedAddressesAreTolled();
6471
check_tolled_zeroAddressNotTolled();
6572
check_tolled_ownAddressNotTolled();
6673

6774
// Fail run if non-zero number of logs.
68-
return (_logs.length == 0, _logs);
75+
return (logs.length == 0, logs);
6976
}
7077

7178
/// @dev Checks that each address expected to be tolled is actually tolled.
@@ -75,8 +82,8 @@ contract ITollChaincheck is Chaincheck {
7582
// Check that each expected address is tolled.
7683
for (uint i; i < expected.length; i++) {
7784
// Using `bud(address)(uint)` to support legacy instances.
78-
if (toll.bud(expected[i]) != 1) {
79-
_logs.push(
85+
if (self.bud(expected[i]) != 1) {
86+
logs.push(
8087
string.concat(
8188
StdStyle.red("Expected address not tolled: "),
8289
vm.toString(expected[i])
@@ -91,40 +98,43 @@ contract ITollChaincheck is Chaincheck {
9198
/// @dev Only non-legacy versions supported.
9299
function check_tolled_onlyExpectedAddressesAreTolled() internal notLegacy {
93100
address[] memory expected = config.readAddressArray(".IToll.tolled");
94-
address[] memory actual = toll.tolled();
101+
address[] memory actual = self.tolled();
95102

96103
for (uint i; i < actual.length; i++) {
104+
bool found = false;
105+
97106
for (uint j; j < expected.length; j++) {
98107
if (actual[i] == expected[j]) {
108+
found = true;
99109
break; // Found address. Continue with outer loop.
100110
}
111+
}
101112

102-
// Log if unknown address tolled.
103-
if (j == expected.length - 1) {
104-
_logs.push(
105-
string.concat(
106-
StdStyle.red("Unknown address tolled: "),
107-
vm.toString(actual[i])
108-
)
109-
);
110-
}
113+
// Log if unknown address tolled.
114+
if (!found) {
115+
logs.push(
116+
string.concat(
117+
StdStyle.red("Unknown address tolled: "),
118+
vm.toString(actual[i])
119+
)
120+
);
111121
}
112122
}
113123
}
114124

115125
/// @dev Checks that the zero address is not tolled.
116126
function check_tolled_zeroAddressNotTolled() internal {
117127
// Using `bud(address)(uint)` to support legacy instances.
118-
if (toll.bud(address(0)) != 0) {
119-
_logs.push(StdStyle.red("Zero address tolled"));
128+
if (self.bud(address(0)) != 0) {
129+
logs.push(StdStyle.red("Zero address tolled"));
120130
}
121131
}
122132

123133
/// @dev Checks that own address is not tolled.
124134
function check_tolled_ownAddressNotTolled() internal {
125135
// Using `bud(address)(uint)` to support legacy instances.
126-
if (toll.bud(address(toll)) != 0) {
127-
_logs.push(StdStyle.red("Own address tolled"));
136+
if (self.bud(address(self)) != 0) {
137+
logs.push(StdStyle.red("Own address tolled"));
128138
}
129139
}
130140
}

0 commit comments

Comments
 (0)