AccessManager.sol 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. import {IAccessManager} from "./IAccessManager.sol";
  4. import {IManaged} from "./IManaged.sol";
  5. import {IAuthority} from "./IAuthority.sol";
  6. import {AccessManagedAdapter} from "./utils/AccessManagedAdapter.sol";
  7. import {Address} from "../../utils/Address.sol";
  8. import {Context} from "../../utils/Context.sol";
  9. import {Multicall} from "../../utils/Multicall.sol";
  10. import {Time} from "../../utils/types/Time.sol";
  11. /**
  12. * @dev AccessManager is a central contract to store the permissions of a system.
  13. *
  14. * The smart contracts under the control of an AccessManager instance will have a set of "restricted" functions, and the
  15. * exact details of how access is restricted for each of those functions is configurable by the admins of the instance.
  16. * These restrictions are expressed in terms of "groups".
  17. *
  18. * An AccessManager instance will define a set of groups. Accounts can be added into any number of these groups. Each of
  19. * them defines a role, and may confer access to some of the restricted functions in the system, as configured by admins
  20. * through the use of {setFunctionAllowedGroup}.
  21. *
  22. * Note that a function in a target contract may become permissioned in this way only when: 1) said contract is
  23. * {AccessManaged} and is connected to this contract as its manager, and 2) said function is decorated with the
  24. * `restricted` modifier.
  25. *
  26. * There is a special group defined by default named "public" which all accounts automatically have.
  27. *
  28. * Contracts where functions are mapped to groups are said to be in a "custom" mode, but contracts can also be
  29. * configured in two special modes: 1) the "open" mode, where all functions are allowed to the "public" group, and 2)
  30. * the "closed" mode, where no function is allowed to any group.
  31. *
  32. * Since all the permissions of the managed system can be modified by the admins of this instance, it is expected that
  33. * they will be highly secured (e.g., a multisig or a well-configured DAO).
  34. *
  35. * NOTE: This contract implements a form of the {IAuthority} interface, but {canCall} has additional return data so it
  36. * doesn't inherit `IAuthority`. It is however compatible with the `IAuthority` interface since the first 32 bytes of
  37. * the return data are a boolean as expected by that interface.
  38. */
  39. contract AccessManager is Context, Multicall, IAccessManager {
  40. using Time for *;
  41. uint256 public constant ADMIN_GROUP = type(uint256).min; // 0
  42. uint256 public constant PUBLIC_GROUP = type(uint256).max; // 2**256-1
  43. mapping(address target => AccessMode mode) private _contractMode;
  44. mapping(address target => mapping(bytes4 selector => uint256 groupId)) private _allowedGroups;
  45. mapping(uint256 groupId => Group) private _groups;
  46. mapping(bytes32 operationId => uint48 schedule) private _schedules;
  47. // This should be transcient storage when supported by the EVM.
  48. bytes32 private _relayIdentifier;
  49. /**
  50. * @dev Check that the caller has a given permission level (`groupId`). Note that this does NOT consider execution
  51. * delays that may be associated to that group.
  52. */
  53. modifier onlyGroup(uint256 groupId) {
  54. address msgsender = _msgSender();
  55. if (!hasGroup(groupId, msgsender)) {
  56. revert AccessControlUnauthorizedAccount(msgsender, groupId);
  57. }
  58. _;
  59. }
  60. constructor(address initialAdmin) {
  61. // admin is active immediately and without any execution delay.
  62. _grantGroup(ADMIN_GROUP, initialAdmin, 0, 0);
  63. }
  64. // =================================================== GETTERS ====================================================
  65. /**
  66. * @dev Check if an address (`caller`) is authorised to call a given function on a given contract directly (with
  67. * no restriction). Additionally, it returns the delay needed to perform the call indirectly through the {schedule}
  68. * & {relay} workflow.
  69. *
  70. * This function is usually called by the targeted contract to control immediate execution of restricted functions.
  71. * Therefore we only return true is the call can be performed without any delay. If the call is subject to a delay,
  72. * then the function should return false, and the caller should schedule the operation for future execution.
  73. *
  74. * We may be able to hash the operation, and check if the call was scheduled, but we would not be able to cleanup
  75. * the schedule, leaving the possibility of multiple executions. Maybe this function should not be view?
  76. *
  77. * NOTE: The IAuthority interface does not include the `uint32` delay. This is an extension of that interface that
  78. * is backward compatible. Some contract may thus ignore the second return argument. In that case they will fail
  79. * to identify the indirect workflow, and will consider call that require a delay to be forbidden.
  80. */
  81. function canCall(address caller, address target, bytes4 selector) public view virtual returns (bool, uint32) {
  82. AccessMode mode = getContractMode(target);
  83. if (mode == AccessMode.Open) {
  84. return (true, 0);
  85. } else if (mode == AccessMode.Closed) {
  86. return (false, 0);
  87. } else if (caller == address(this)) {
  88. // Caller is AccessManager => call was relayed. In that case the relay already checked permissions. We
  89. // verify that the call "identifier", which is set during the relay call, is correct.
  90. return (_relayIdentifier == keccak256(abi.encodePacked(target, selector)), 0);
  91. } else {
  92. uint256 groupId = getFunctionAllowedGroup(target, selector);
  93. bool inGroup = hasGroup(groupId, caller);
  94. uint32 executeDelay = inGroup ? getAccess(groupId, caller).delay.get() : 0;
  95. return (inGroup && executeDelay == 0, executeDelay);
  96. }
  97. }
  98. /**
  99. * @dev Get the mode under which a contract is operating.
  100. */
  101. function getContractMode(address target) public view virtual returns (AccessMode) {
  102. return _contractMode[target];
  103. }
  104. /**
  105. * @dev Get the permission level (group) required to call a function. This only applies for contract that are
  106. * operating under the `Custom` mode.
  107. */
  108. function getFunctionAllowedGroup(address target, bytes4 selector) public view virtual returns (uint256) {
  109. return _allowedGroups[target][selector];
  110. }
  111. /**
  112. * @dev Get the id of the group that acts as an admin for given group.
  113. *
  114. * The admin permission is required to grant the group, revoke the group and update the execution delay to execute
  115. * an operation that is restricted to this group.
  116. */
  117. function getGroupAdmin(uint256 groupId) public view virtual returns (uint256) {
  118. return _groups[groupId].admin;
  119. }
  120. /**
  121. * @dev Get the group that acts as a guardian for a given group.
  122. *
  123. * The guardian permission allows canceling operations that have been scheduled under the group.
  124. */
  125. function getGroupGuardian(uint256 groupId) public view virtual returns (uint256) {
  126. return _groups[groupId].guardian;
  127. }
  128. /**
  129. * @dev Get the group current grant delay, that value may change at any point, without an event emitted, following
  130. * a call to {setGrantDelay}. Changes to this value, including effect timepoint are notified by the
  131. * {GroupGrantDelayChanged} event.
  132. */
  133. function getGroupGrantDelay(uint256 groupId) public view virtual returns (uint32) {
  134. return _groups[groupId].delay.get();
  135. }
  136. /**
  137. * @dev Get the access details for a given account in a given group. These details include the timepoint at which
  138. * membership becomes active, and the delay applied to all operation by this user that require this permission
  139. * level.
  140. */
  141. function getAccess(uint256 groupId, address account) public view virtual returns (Access memory) {
  142. return _groups[groupId].members[account];
  143. }
  144. /**
  145. * @dev Check if a given account currently had the permission level corresponding to a given group. Note that this
  146. * permission might be associated with a delay. {getAccess} can provide more details.
  147. */
  148. function hasGroup(uint256 groupId, address account) public view virtual returns (bool) {
  149. return groupId == PUBLIC_GROUP || getAccess(groupId, account).since.isSetAndPast(Time.timestamp());
  150. }
  151. // =============================================== GROUP MANAGEMENT ===============================================
  152. /**
  153. * @dev Give a label to a group, for improved group discoverabily by UIs.
  154. *
  155. * Emits a {GroupLabel} event.
  156. */
  157. function labelGroup(uint256 groupId, string calldata label) public virtual onlyGroup(ADMIN_GROUP) {
  158. emit GroupLabel(groupId, label);
  159. }
  160. /**
  161. * @dev Give permission to an account to execute function restricted to a group. Optionally, a delay can be
  162. * enforced for any function call, byt this user, that require this level of permission. This call is only
  163. * effective after a grant delay that is specific to the group being granted.
  164. *
  165. * Requirements:
  166. *
  167. * - the caller must be in the group's admins
  168. *
  169. * Emits a {GroupGranted} event
  170. */
  171. function grantGroup(
  172. uint256 groupId,
  173. address account,
  174. uint32 executionDelay
  175. ) public virtual onlyGroup(getGroupAdmin(groupId)) {
  176. _grantGroup(groupId, account, getGroupGrantDelay(groupId), executionDelay);
  177. }
  178. /**
  179. * @dev Remove an account for a group, with immediate effect.
  180. *
  181. * Requirements:
  182. *
  183. * - the caller must be in the group's admins
  184. *
  185. * Emits a {GroupRevoked} event
  186. */
  187. function revokeGroup(uint256 groupId, address account) public virtual onlyGroup(getGroupAdmin(groupId)) {
  188. _revokeGroup(groupId, account);
  189. }
  190. /**
  191. * @dev Renounce group permissions for the calling account, with immediate effect.
  192. *
  193. * Requirements:
  194. *
  195. * - the caller must be `callerConfirmation`.
  196. *
  197. * Emits a {GroupRevoked} event
  198. */
  199. function renounceGroup(uint256 groupId, address callerConfirmation) public virtual {
  200. if (callerConfirmation != _msgSender()) {
  201. revert AccessManagerBadConfirmation();
  202. }
  203. _revokeGroup(groupId, callerConfirmation);
  204. }
  205. /**
  206. * @dev Set the execution delay for a given account in a given group. This update is not immediate and follows the
  207. * delay rules. For example, If a user currently has a delay of 3 hours, and this is called to reduce that delay to
  208. * 1 hour, the new delay will take some time to take effect, enforcing that any operation executed in the 3 hours
  209. * that follows this update was indeed scheduled before this update.
  210. *
  211. * Requirements:
  212. *
  213. * - the caller must be in the group's admins
  214. *
  215. * Emits a {GroupExecutionDelayUpdate} event
  216. */
  217. function setExecuteDelay(
  218. uint256 groupId,
  219. address account,
  220. uint32 newDelay
  221. ) public virtual onlyGroup(getGroupAdmin(groupId)) {
  222. _setExecuteDelay(groupId, account, newDelay);
  223. }
  224. /**
  225. * @dev Change admin group for a given group.
  226. *
  227. * Requirements:
  228. *
  229. * - the caller must be a global admin
  230. *
  231. * Emits a {GroupAdminChanged} event
  232. */
  233. function setGroupAdmin(uint256 groupId, uint256 admin) public virtual onlyGroup(ADMIN_GROUP) {
  234. _setGroupAdmin(groupId, admin);
  235. }
  236. /**
  237. * @dev Change guardian group for a given group.
  238. *
  239. * Requirements:
  240. *
  241. * - the caller must be a global admin
  242. *
  243. * Emits a {GroupGuardianChanged} event
  244. */
  245. function setGroupGuardian(uint256 groupId, uint256 guardian) public virtual onlyGroup(ADMIN_GROUP) {
  246. _setGroupGuardian(groupId, guardian);
  247. }
  248. /**
  249. * @dev Update the .
  250. *
  251. * Requirements:
  252. *
  253. * - the caller must be a global admin
  254. *
  255. * Emits a {GroupGrantDelayChanged} event
  256. */
  257. function setGrantDelay(uint256 groupId, uint32 newDelay) public virtual onlyGroup(ADMIN_GROUP) {
  258. _setGrantDelay(groupId, newDelay);
  259. }
  260. /**
  261. * @dev Internal version of {grantGroup} without access control.
  262. *
  263. * Emits a {GroupGranted} event
  264. */
  265. function _grantGroup(uint256 groupId, address account, uint32 grantDelay, uint32 executionDelay) internal virtual {
  266. if (groupId == PUBLIC_GROUP) {
  267. revert AccessManagerLockedGroup(groupId);
  268. } else if (_groups[groupId].members[account].since != 0) {
  269. revert AccessManagerAcountAlreadyInGroup(groupId, account);
  270. }
  271. uint48 since = Time.timestamp() + grantDelay;
  272. _groups[groupId].members[account] = Access({since: since, delay: executionDelay.toDelay()});
  273. emit GroupGranted(groupId, account, since, executionDelay);
  274. }
  275. /**
  276. * @dev Internal version of {revokeGroup} without access control. This logic is also used by {renounceGroup}.
  277. *
  278. * Emits a {GroupRevoked} event
  279. */
  280. function _revokeGroup(uint256 groupId, address account) internal virtual {
  281. if (groupId == PUBLIC_GROUP) {
  282. revert AccessManagerLockedGroup(groupId);
  283. } else if (_groups[groupId].members[account].since == 0) {
  284. revert AccessManagerAcountNotInGroup(groupId, account);
  285. }
  286. delete _groups[groupId].members[account];
  287. emit GroupRevoked(groupId, account);
  288. }
  289. /**
  290. * @dev Internal version of {setExecuteDelay} without access control.
  291. *
  292. * Emits a {GroupExecutionDelayUpdate} event
  293. */
  294. function _setExecuteDelay(uint256 groupId, address account, uint32 newDuration) internal virtual {
  295. if (groupId == PUBLIC_GROUP) {
  296. revert AccessManagerLockedGroup(groupId);
  297. } else if (_groups[groupId].members[account].since == 0) {
  298. revert AccessManagerAcountNotInGroup(groupId, account);
  299. }
  300. Time.Delay newDelay = _groups[groupId].members[account].delay.update(newDuration, 0); // TODO: minsetback ?
  301. _groups[groupId].members[account].delay = newDelay;
  302. (, , uint48 effectPoint) = newDelay.split();
  303. emit GroupExecutionDelayUpdate(groupId, account, newDuration, effectPoint);
  304. }
  305. /**
  306. * @dev Internal version of {setGroupAdmin} without access control.
  307. *
  308. * Emits a {GroupAdminChanged} event
  309. */
  310. function _setGroupAdmin(uint256 groupId, uint256 admin) internal virtual {
  311. if (groupId == ADMIN_GROUP || groupId == PUBLIC_GROUP) {
  312. revert AccessManagerLockedGroup(groupId);
  313. }
  314. _groups[groupId].admin = admin;
  315. emit GroupAdminChanged(groupId, admin);
  316. }
  317. /**
  318. * @dev Internal version of {setGroupGuardian} without access control.
  319. *
  320. * Emits a {GroupGuardianChanged} event
  321. */
  322. function _setGroupGuardian(uint256 groupId, uint256 guardian) internal virtual {
  323. if (groupId == ADMIN_GROUP || groupId == PUBLIC_GROUP) {
  324. revert AccessManagerLockedGroup(groupId);
  325. }
  326. _groups[groupId].guardian = guardian;
  327. emit GroupGuardianChanged(groupId, guardian);
  328. }
  329. /**
  330. * @dev Internal version of {setGrantDelay} without access control.
  331. *
  332. * Emits a {GroupGrantDelayChanged} event
  333. */
  334. function _setGrantDelay(uint256 groupId, uint32 newDelay) internal virtual {
  335. if (groupId == PUBLIC_GROUP) {
  336. revert AccessManagerLockedGroup(groupId);
  337. }
  338. Time.Delay updated = _groups[groupId].delay.update(newDelay, 0); // TODO: minsetback ?
  339. _groups[groupId].delay = updated;
  340. (, , uint48 effect) = updated.split();
  341. emit GroupGrantDelayChanged(groupId, newDelay, effect);
  342. }
  343. // ============================================= FUNCTION MANAGEMENT ==============================================
  344. /**
  345. * @dev Set the level of permission (`group`) required to call functions identified by the `selectors` in the
  346. * `target` contract.
  347. *
  348. * Requirements:
  349. *
  350. * - the caller must be a global admin
  351. *
  352. * Emits a {FunctionAllowedGroupUpdated} event per selector
  353. */
  354. function setFunctionAllowedGroup(
  355. address target,
  356. bytes4[] calldata selectors,
  357. uint256 groupId
  358. ) public virtual onlyGroup(ADMIN_GROUP) {
  359. // todo set delay or document risks
  360. for (uint256 i = 0; i < selectors.length; ++i) {
  361. _setFunctionAllowedGroup(target, selectors[i], groupId);
  362. }
  363. }
  364. /**
  365. * @dev Internal version of {setFunctionAllowedGroup} without access control.
  366. *
  367. * Emits a {FunctionAllowedGroupUpdated} event
  368. */
  369. function _setFunctionAllowedGroup(address target, bytes4 selector, uint256 groupId) internal virtual {
  370. _allowedGroups[target][selector] = groupId;
  371. emit FunctionAllowedGroupUpdated(target, selector, groupId);
  372. }
  373. // =============================================== MODE MANAGEMENT ================================================
  374. /**
  375. * @dev Set the operating mode of a contract to Custom. This enables the group mechanism for per-function access
  376. * restriction and delay enforcement.
  377. *
  378. * Requirements:
  379. *
  380. * - the caller must be a global admin
  381. *
  382. * Emits a {AccessModeUpdated} event.
  383. */
  384. function setContractModeCustom(address target) public virtual onlyGroup(ADMIN_GROUP) {
  385. // todo set delay or document risks
  386. _setContractMode(target, AccessMode.Custom);
  387. }
  388. /**
  389. * @dev Set the operating mode of a contract to Open. This allows anyone to call any `restricted()` function with
  390. * no delay.
  391. *
  392. * Requirements:
  393. *
  394. * - the caller must be a global admin
  395. *
  396. * Emits a {AccessModeUpdated} event.
  397. */
  398. function setContractModeOpen(address target) public virtual onlyGroup(ADMIN_GROUP) {
  399. // todo set delay or document risks
  400. _setContractMode(target, AccessMode.Open);
  401. }
  402. /**
  403. * @dev Set the operating mode of a contract to Close. This prevents anyone from calling any `restricted()`
  404. * function.
  405. *
  406. * Requirements:
  407. *
  408. * - the caller must be a global admin
  409. *
  410. * Emits a {AccessModeUpdated} event.
  411. */
  412. function setContractModeClosed(address target) public virtual onlyGroup(ADMIN_GROUP) {
  413. // todo set delay or document risks
  414. _setContractMode(target, AccessMode.Closed);
  415. }
  416. /**
  417. * @dev Set the operating mode of a contract. This is an internal setter with no access restrictions.
  418. *
  419. * Emits a {AccessModeUpdated} event.
  420. */
  421. function _setContractMode(address target, AccessMode mode) internal virtual {
  422. _contractMode[target] = mode;
  423. emit AccessModeUpdated(target, mode);
  424. }
  425. // ============================================== DELAYED OPERATIONS ==============================================
  426. /**
  427. * @dev Return the timepoint at which a scheduled operation will be ready for execution. This returns 0 if the
  428. * operation is not yet scheduled, was executed or was canceled.
  429. */
  430. function getSchedule(bytes32 id) public view virtual returns (uint48) {
  431. return _schedules[id];
  432. }
  433. /**
  434. * @dev Schedule a delayed operation, and return the operation identifier.
  435. *
  436. * Emits a {Scheduled} event.
  437. */
  438. function schedule(address target, bytes calldata data) public virtual returns (bytes32) {
  439. address caller = _msgSender();
  440. bytes4 selector = bytes4(data[0:4]);
  441. // Fetch restriction to that apply to the caller on the targeted function
  442. (bool allowed, uint32 setback) = canCall(caller, target, selector);
  443. // If caller is not authorised, revert
  444. if (!allowed && setback == 0) {
  445. revert AccessManagerUnauthorizedCall(caller, target, selector);
  446. }
  447. // If caller is authorised, schedule operation
  448. bytes32 operationId = _hashOperation(caller, target, data);
  449. if (_schedules[operationId] != 0) {
  450. revert AccessManagerAlreadyScheduled(operationId);
  451. }
  452. _schedules[operationId] = Time.timestamp() + setback;
  453. emit Scheduled(operationId, caller, target, data);
  454. return operationId;
  455. }
  456. /**
  457. * @dev Execute a function that is delay restricted, provided it was properly scheduled beforehand, or the
  458. * execution delay is 0.
  459. *
  460. * Emits a {Executed} event if the call was scheduled. Unscheduled call (with no delay) do not emit that event.
  461. */
  462. function relay(address target, bytes calldata data) public payable virtual {
  463. relayViaAdapter(target, data, address(0));
  464. }
  465. /**
  466. * @dev Execute a function that is delay restricted in the same way as {relay} but through an
  467. * {AccessManagedAdapter}.
  468. */
  469. function relayViaAdapter(address target, bytes calldata data, address adapter) public payable virtual {
  470. address caller = _msgSender();
  471. bytes4 selector = bytes4(data[0:4]);
  472. // Fetch restriction to that apply to the caller on the targeted function
  473. (bool allowed, uint32 setback) = canCall(caller, target, selector);
  474. // If caller is not authorised, revert
  475. if (!allowed && setback == 0) {
  476. revert AccessManagerUnauthorizedCall(caller, target, selector);
  477. }
  478. // If caller is authorised, check operation was scheduled early enough
  479. bytes32 operationId = _hashOperation(caller, target, data);
  480. uint48 timepoint = _schedules[operationId];
  481. if (setback != 0) {
  482. if (timepoint == 0) {
  483. revert AccessManagerNotScheduled(operationId);
  484. } else if (timepoint > Time.timestamp()) {
  485. revert AccessManagerNotReady(operationId);
  486. }
  487. }
  488. if (timepoint != 0) {
  489. delete _schedules[operationId];
  490. emit Executed(operationId);
  491. }
  492. // Mark the target and selector as authorised
  493. bytes32 relayIdentifierBefore = _relayIdentifier;
  494. _relayIdentifier = keccak256(abi.encodePacked(target, selector));
  495. if (adapter != address(0)) {
  496. // Perform call through adapter
  497. AccessManagedAdapter(adapter).relay{value: msg.value}(target, data);
  498. } else {
  499. // Perform call directly
  500. Address.functionCallWithValue(target, data, msg.value);
  501. }
  502. // Reset relay identifier
  503. _relayIdentifier = relayIdentifierBefore;
  504. }
  505. /**
  506. * @dev Cancel a scheduled (delayed) operation.
  507. *
  508. * Requirements:
  509. *
  510. * - the caller must be the proposer, or a guardian of the targeted function
  511. *
  512. * Emits a {Canceled} event.
  513. */
  514. function cancel(address caller, address target, bytes calldata data) public virtual {
  515. address msgsender = _msgSender();
  516. bytes4 selector = bytes4(data[0:4]);
  517. bytes32 operationId = _hashOperation(caller, target, data);
  518. if (_schedules[operationId] == 0) {
  519. revert AccessManagerNotScheduled(operationId);
  520. } else if (
  521. caller != msgsender &&
  522. !hasGroup(ADMIN_GROUP, msgsender) &&
  523. !hasGroup(getGroupGuardian(getFunctionAllowedGroup(target, selector)), msgsender)
  524. ) {
  525. // calls can only be canceled by the account that scheduled them, a global admin, or by a guardian of the required group.
  526. revert AccessManagerCannotCancel(msgsender, caller, target, selector);
  527. }
  528. delete _schedules[operationId];
  529. emit Canceled(operationId);
  530. }
  531. /**
  532. * @dev Hashing function for delayed operations
  533. */
  534. function _hashOperation(address caller, address target, bytes calldata data) private pure returns (bytes32) {
  535. return keccak256(abi.encode(caller, target, data));
  536. }
  537. // ==================================================== OTHERS ====================================================
  538. /**
  539. * @dev Change the AccessManager instance used by a contract that correctly uses this instance.
  540. *
  541. * Requirements:
  542. *
  543. * - the caller must be a global admin
  544. */
  545. function updateAuthority(IManaged target, address newAuthority) public virtual onlyGroup(ADMIN_GROUP) {
  546. // todo set delay or document risks
  547. target.setAuthority(newAuthority);
  548. }
  549. }