Skip to content

Commit 8731d53

Browse files
committed
Replace OZ AccessControl with CL SimpleWriteAccessController
1 parent 27ecfda commit 8731d53

File tree

6 files changed

+192
-339
lines changed

6 files changed

+192
-339
lines changed

contracts/v0.7/bridge/token/LinkTokenChild.sol

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,19 @@ import { TypeAndVersionInterface } from "../../../v0.6/TypeAndVersionInterface.s
66
import { IERC20Child } from "./IERC20Child.sol";
77

88
/* Contract Imports */
9-
import { AccessControl } from "../../../vendor/@openzeppelin/contracts/3.4.1/contracts/access/AccessControl.sol";
9+
import { SimpleWriteAccessController } from "../../../vendor/@chainlink/contracts/0.1.7/contracts/v0.6/SimpleWriteAccessController.sol";
1010
import { LinkToken } from "../../../v0.6/LinkToken.sol";
1111

1212
/// @dev Access controlled mintable & burnable LinkToken, for use on sidechains and L2 networks.
13-
contract LinkTokenChild is TypeAndVersionInterface, IERC20Child, AccessControl, LinkToken {
14-
// Using this role the bridge gateway can deposit/withdraw (mint/burn)
15-
bytes32 public constant BRIDGE_GATEWAY_ROLE = keccak256("BRIDGE_GATEWAY_ROLE");
16-
13+
contract LinkTokenChild is TypeAndVersionInterface, IERC20Child, SimpleWriteAccessController, LinkToken {
1714
/**
1815
* @dev Overrides parent contract so no tokens are minted on deployment.
1916
* @inheritdoc LinkToken
2017
*/
2118
function _onCreate()
2219
internal
2320
override
24-
{
25-
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
26-
}
21+
{}
2722

2823
/**
2924
* @notice versions:
@@ -43,7 +38,7 @@ contract LinkTokenChild is TypeAndVersionInterface, IERC20Child, AccessControl,
4338
}
4439

4540
/**
46-
* @dev Only callable by account with BRIDGE_GATEWAY_ROLE
41+
* @dev Only callable by account with access (gateway role)
4742
* @inheritdoc IERC20Child
4843
*/
4944
function deposit(
@@ -53,13 +48,13 @@ contract LinkTokenChild is TypeAndVersionInterface, IERC20Child, AccessControl,
5348
external
5449
override
5550
virtual
56-
onlyRole(BRIDGE_GATEWAY_ROLE)
51+
checkAccess()
5752
{
5853
_mint(recipient, amount);
5954
}
6055

6156
/**
62-
* @dev Only callable by account with BRIDGE_GATEWAY_ROLE
57+
* @dev Only callable by account with access (gateway role)
6358
* @inheritdoc IERC20Child
6459
*/
6560
function withdraw(
@@ -68,19 +63,8 @@ contract LinkTokenChild is TypeAndVersionInterface, IERC20Child, AccessControl,
6863
external
6964
override
7065
virtual
71-
onlyRole(BRIDGE_GATEWAY_ROLE)
66+
checkAccess()
7267
{
7368
_burn(_msgSender(), amount);
7469
}
75-
76-
/**
77-
* @dev Modifier to check access by role.
78-
* @param role the required role
79-
*/
80-
modifier onlyRole(
81-
bytes32 role
82-
) {
83-
require(hasRole(role, _msgSender()), "LinkTokenChild: missing role");
84-
_;
85-
}
8670
}

contracts/vendor/@chainlink/contracts/0.1.7/contracts/v0.6/Owned.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: MIT
2-
pragma solidity ^0.6.0;
2+
// next-line updated from source
3+
pragma solidity >0.6.0 <0.8.0;
34

45
/**
56
* @title The Owned contract
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// SPDX-License-Identifier: MIT
2+
// next-line updated from source
3+
pragma solidity >0.6.0 <0.8.0;
4+
5+
import "./Owned.sol";
6+
import "./interfaces/AccessControllerInterface.sol";
7+
8+
/**
9+
* @title SimpleWriteAccessController
10+
* @notice Gives access to accounts explicitly added to an access list by the
11+
* controller's owner.
12+
* @dev does not make any special permissions for externally, see
13+
* SimpleReadAccessController for that.
14+
*/
15+
contract SimpleWriteAccessController is AccessControllerInterface, Owned {
16+
17+
bool public checkEnabled;
18+
mapping(address => bool) internal accessList;
19+
20+
event AddedAccess(address user);
21+
event RemovedAccess(address user);
22+
event CheckAccessEnabled();
23+
event CheckAccessDisabled();
24+
25+
constructor()
26+
public
27+
{
28+
checkEnabled = true;
29+
}
30+
31+
/**
32+
* @notice Returns the access of an address
33+
* @param _user The address to query
34+
*/
35+
function hasAccess(
36+
address _user,
37+
bytes memory
38+
)
39+
public
40+
view
41+
virtual
42+
override
43+
returns (bool)
44+
{
45+
return accessList[_user] || !checkEnabled;
46+
}
47+
48+
/**
49+
* @notice Adds an address to the access list
50+
* @param _user The address to add
51+
*/
52+
function addAccess(address _user)
53+
external
54+
onlyOwner()
55+
{
56+
if (!accessList[_user]) {
57+
accessList[_user] = true;
58+
59+
emit AddedAccess(_user);
60+
}
61+
}
62+
63+
/**
64+
* @notice Removes an address from the access list
65+
* @param _user The address to remove
66+
*/
67+
function removeAccess(address _user)
68+
external
69+
onlyOwner()
70+
{
71+
if (accessList[_user]) {
72+
accessList[_user] = false;
73+
74+
emit RemovedAccess(_user);
75+
}
76+
}
77+
78+
/**
79+
* @notice makes the access check enforced
80+
*/
81+
function enableAccessCheck()
82+
external
83+
onlyOwner()
84+
{
85+
if (!checkEnabled) {
86+
checkEnabled = true;
87+
88+
emit CheckAccessEnabled();
89+
}
90+
}
91+
92+
/**
93+
* @notice makes the access check unenforced
94+
*/
95+
function disableAccessCheck()
96+
external
97+
onlyOwner()
98+
{
99+
if (checkEnabled) {
100+
checkEnabled = false;
101+
102+
emit CheckAccessDisabled();
103+
}
104+
}
105+
106+
/**
107+
* @dev reverts if the caller does not have access
108+
*/
109+
modifier checkAccess() {
110+
require(hasAccess(msg.sender, msg.data), "No access");
111+
_;
112+
}
113+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-License-Identifier: MIT
2+
// next-line updated from source
3+
pragma solidity >0.6.0 <0.8.0;
4+
5+
interface AccessControllerInterface {
6+
function hasAccess(address user, bytes calldata data) external view returns (bool);
7+
}

0 commit comments

Comments
 (0)