Skip to content

Commit d42b0c7

Browse files
committed
auth: Fix deployment initially authed issue
1 parent d7012ce commit d42b0c7

File tree

6 files changed

+44
-40
lines changed

6 files changed

+44
-40
lines changed

Diff for: script/IAuthChaincheck.sol

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ import {IAuth} from "src/auth/IAuth.sol";
1313
* @notice IAuth's `chaincheck` Integration Test
1414
*
1515
* @dev Config Definition:
16-
* ```json
17-
* {
18-
* "IAuth": {
19-
* "legacy": bool,
20-
* "authed": [
21-
* "0x000000000000000000000000000000000000cafe",
22-
* ...
23-
* ]
24-
* }
25-
* }
26-
* ```
16+
* ```json
17+
* {
18+
* "IAuth": {
19+
* "legacy": bool,
20+
* "authed": [
21+
* "<Ethereum address>",
22+
* ...
23+
* ]
24+
* }
25+
* }
26+
* ```
2727
*/
2828
contract IAuthChaincheck is Chaincheck {
2929
using stdJson for string;

Diff for: script/ITollChaincheck.sol

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ import {IToll} from "src/toll/IToll.sol";
1414
* @notice IToll's `chaincheck` Integration Test
1515
*
1616
* @dev Config Definition:
17-
* ```json
18-
* {
19-
* "IToll": {
20-
* "legacy": bool,
21-
* "tolled": [
22-
* "0x000000000000000000000000000000000000cafe",
23-
* ...
24-
* ]
25-
* }
26-
* }
27-
* ```
17+
* ```json
18+
* {
19+
* "IToll": {
20+
* "legacy": bool,
21+
* "tolled": [
22+
* "<Ethereum address>",
23+
* ...
24+
* ]
25+
* }
26+
* }
27+
* ```
2828
*/
2929
contract ITollChaincheck is Chaincheck {
3030
using stdJson for string;

Diff for: src/auth/Auth.sol

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {IAuth} from "./IAuth.sol";
1010
* where a set of addresses are granted access to protected functions.
1111
* These addresses are said to be _auth'ed_.
1212
*
13-
* Initially, the deployer address is the only address auth'ed. Through
14-
* the `rely(address)` and `deny(address)` functions, auth'ed callers are
15-
* able to grant/renounce auth to/from addresses.
13+
* Initially, the address given as constructor argument is the only address
14+
* auth'ed. Through the `rely(address)` and `deny(address)` functions,
15+
* auth'ed callers are able to grant/renounce auth to/from addresses.
1616
*
1717
* This module is used through inheritance. It will make available the
1818
* modifier `auth`, which can be applied to functions to restrict their
@@ -22,8 +22,8 @@ abstract contract Auth is IAuth {
2222
/// @dev Mapping storing whether address is auth'ed.
2323
/// @custom:invariant Image of mapping is {0, 1}.
2424
/// ∀x ∊ Address: _wards[x] ∊ {0, 1}
25-
/// @custom:invariant Only deployer address authenticated after deployment.
26-
/// deployment → (∀x ∊ Address: _wards[x] == 1 → x == msg.sender)
25+
/// @custom:invariant Only address given as constructor argument is authenticated after deployment.
26+
/// deploy(initialAuthed) → (∀x ∊ Address: _wards[x] == 1 → x == initialAuthed)
2727
/// @custom:invariant Only functions `rely` and `deny` may mutate the mapping's state.
2828
/// ∀x ∊ Address: preTx(_wards[x]) != postTx(_wards[x])
2929
/// → (msg.sig == "rely" ∨ msg.sig == "deny")
@@ -60,13 +60,13 @@ abstract contract Auth is IAuth {
6060
_;
6161
}
6262

63-
constructor() {
64-
_wards[msg.sender] = 1;
65-
_wardsTouched.push(msg.sender);
63+
constructor(address initialAuthed) {
64+
_wards[initialAuthed] = 1;
65+
_wardsTouched.push(initialAuthed);
6666

67-
// Note to use address(0) as caller to keep invariant that no address
68-
// can grant itself auth.
69-
emit AuthGranted(address(0), msg.sender);
67+
// Note to use address(0) as caller to indicate address was auth'ed
68+
// during deployment.
69+
emit AuthGranted(address(0), initialAuthed);
7070
}
7171

7272
/// @inheritdoc IAuth

Diff for: test/auth/Auth.t.sol

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ import {IAuthInvariantTest} from "./IAuthInvariantTest.sol";
66

77
import {Auth} from "src/auth/Auth.sol";
88

9-
contract AuthInstance is Auth {}
9+
contract AuthInstance is Auth {
10+
constructor(address initialAuthed) Auth(initialAuthed) {}
11+
}
1012

1113
contract AuthTest is IAuthTest {
1214
function setUp() public {
13-
setUp(new AuthInstance());
15+
setUp(new AuthInstance(address(this)));
1416
}
1517
}
1618

1719
contract AuthInvariantTest is IAuthInvariantTest {
1820
function setUp() public {
19-
setUp(new AuthInstance());
21+
setUp(new AuthInstance(address(this)));
2022
}
2123
}

Diff for: test/auth/IAuthTest.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ abstract contract IAuthTest is Test {
1919
}
2020

2121
function test_deployment() public {
22-
// Deployer is auth'ed.
22+
// Address given as constructor argument is auth'ed.
2323
assertTrue(auth.authed(address(this)));
2424

25-
// Deployer is included in authed list.
25+
// Address given as constructor is included in authed list.
2626
address[] memory authed = auth.authed();
2727
assertEq(authed.length, 1);
2828
assertEq(authed[0], address(this));

Diff for: test/toll/Toll.t.sol

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ import {Toll} from "src/toll/Toll.sol";
88
import {Auth} from "src/auth/Auth.sol";
99

1010
contract TollInstance is Toll, Auth {
11+
constructor(address initialAuthed) Auth(initialAuthed) {}
12+
1113
function toll_auth() internal override(Toll) auth {}
1214
}
1315

1416
contract TollTest is ITollTest {
1517
function setUp() public {
16-
setUp(new TollInstance());
18+
setUp(new TollInstance(address(this)));
1719
}
1820
}
1921

2022
contract TollInvariantTest is ITollInvariantTest {
2123
function setUp() public {
22-
setUp(new TollInstance());
24+
setUp(new TollInstance(address(this)));
2325
}
2426
}

0 commit comments

Comments
 (0)