Skip to content

Commit

Permalink
auth: Fix deployment initially authed issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pmerkleplant committed Aug 1, 2023
1 parent d7012ce commit d42b0c7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 40 deletions.
22 changes: 11 additions & 11 deletions script/IAuthChaincheck.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import {IAuth} from "src/auth/IAuth.sol";
* @notice IAuth's `chaincheck` Integration Test
*
* @dev Config Definition:
* ```json
* {
* "IAuth": {
* "legacy": bool,
* "authed": [
* "0x000000000000000000000000000000000000cafe",
* ...
* ]
* }
* }
* ```
* ```json
* {
* "IAuth": {
* "legacy": bool,
* "authed": [
* "<Ethereum address>",
* ...
* ]
* }
* }
* ```
*/
contract IAuthChaincheck is Chaincheck {
using stdJson for string;
Expand Down
22 changes: 11 additions & 11 deletions script/ITollChaincheck.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ import {IToll} from "src/toll/IToll.sol";
* @notice IToll's `chaincheck` Integration Test
*
* @dev Config Definition:
* ```json
* {
* "IToll": {
* "legacy": bool,
* "tolled": [
* "0x000000000000000000000000000000000000cafe",
* ...
* ]
* }
* }
* ```
* ```json
* {
* "IToll": {
* "legacy": bool,
* "tolled": [
* "<Ethereum address>",
* ...
* ]
* }
* }
* ```
*/
contract ITollChaincheck is Chaincheck {
using stdJson for string;
Expand Down
22 changes: 11 additions & 11 deletions src/auth/Auth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {IAuth} from "./IAuth.sol";
* where a set of addresses are granted access to protected functions.
* These addresses are said to be _auth'ed_.
*
* Initially, the deployer address is the only address auth'ed. Through
* the `rely(address)` and `deny(address)` functions, auth'ed callers are
* able to grant/renounce auth to/from addresses.
* Initially, the address given as constructor argument is the only address
* auth'ed. Through the `rely(address)` and `deny(address)` functions,
* auth'ed callers are able to grant/renounce auth to/from addresses.
*
* This module is used through inheritance. It will make available the
* modifier `auth`, which can be applied to functions to restrict their
Expand All @@ -22,8 +22,8 @@ abstract contract Auth is IAuth {
/// @dev Mapping storing whether address is auth'ed.
/// @custom:invariant Image of mapping is {0, 1}.
/// ∀x ∊ Address: _wards[x] ∊ {0, 1}
/// @custom:invariant Only deployer address authenticated after deployment.
/// deployment → (∀x ∊ Address: _wards[x] == 1 → x == msg.sender)
/// @custom:invariant Only address given as constructor argument is authenticated after deployment.
/// deploy(initialAuthed) → (∀x ∊ Address: _wards[x] == 1 → x == initialAuthed)
/// @custom:invariant Only functions `rely` and `deny` may mutate the mapping's state.
/// ∀x ∊ Address: preTx(_wards[x]) != postTx(_wards[x])
/// → (msg.sig == "rely" ∨ msg.sig == "deny")
Expand Down Expand Up @@ -60,13 +60,13 @@ abstract contract Auth is IAuth {
_;
}

constructor() {
_wards[msg.sender] = 1;
_wardsTouched.push(msg.sender);
constructor(address initialAuthed) {
_wards[initialAuthed] = 1;
_wardsTouched.push(initialAuthed);

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

/// @inheritdoc IAuth
Expand Down
8 changes: 5 additions & 3 deletions test/auth/Auth.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import {IAuthInvariantTest} from "./IAuthInvariantTest.sol";

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

contract AuthInstance is Auth {}
contract AuthInstance is Auth {
constructor(address initialAuthed) Auth(initialAuthed) {}
}

contract AuthTest is IAuthTest {
function setUp() public {
setUp(new AuthInstance());
setUp(new AuthInstance(address(this)));
}
}

contract AuthInvariantTest is IAuthInvariantTest {
function setUp() public {
setUp(new AuthInstance());
setUp(new AuthInstance(address(this)));
}
}
4 changes: 2 additions & 2 deletions test/auth/IAuthTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ abstract contract IAuthTest is Test {
}

function test_deployment() public {
// Deployer is auth'ed.
// Address given as constructor argument is auth'ed.
assertTrue(auth.authed(address(this)));

// Deployer is included in authed list.
// Address given as constructor is included in authed list.
address[] memory authed = auth.authed();
assertEq(authed.length, 1);
assertEq(authed[0], address(this));
Expand Down
6 changes: 4 additions & 2 deletions test/toll/Toll.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import {Toll} from "src/toll/Toll.sol";
import {Auth} from "src/auth/Auth.sol";

contract TollInstance is Toll, Auth {
constructor(address initialAuthed) Auth(initialAuthed) {}

function toll_auth() internal override(Toll) auth {}
}

contract TollTest is ITollTest {
function setUp() public {
setUp(new TollInstance());
setUp(new TollInstance(address(this)));
}
}

contract TollInvariantTest is ITollInvariantTest {
function setUp() public {
setUp(new TollInstance());
setUp(new TollInstance(address(this)));
}
}

0 comments on commit d42b0c7

Please sign in to comment.