* 4.6.0-rc.0 * Fix release script to only release @openzeppelin/contracts (cherry picked from commit2bd75a44bb) * make ERC2981:royaltyInfo public (#3305) (cherry picked from commitd2832ca7a9) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * add transpilation guards to the crosschain mocks (#3306) (cherry picked from commit9af5af8fff) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * Fix tests on upgradeable contracts after transpilation (cherry picked from commit0762479dd5) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * Remove unused constructor argument (cherry picked from commit69c3781043) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * Bump minimum Solidity version for Initializable.sol to 0.8.2 (#3328) (cherry picked from commitcb14ea3c5c) * Fix update-comment script to ignore invalid tags (cherry picked from commit848fef5b6c) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * 4.6.0 Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
46 lines
1.7 KiB
Solidity
46 lines
1.7 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
// OpenZeppelin Contracts (last updated v4.6.0) (access/AccessControlCrossChain.sol)
|
|
|
|
pragma solidity ^0.8.4;
|
|
|
|
import "./AccessControl.sol";
|
|
import "../crosschain/CrossChainEnabled.sol";
|
|
|
|
/**
|
|
* @dev An extension to {AccessControl} with support for cross-chain access management.
|
|
* For each role, is extension implements an equivalent "aliased" role that is used for
|
|
* restricting calls originating from other chains.
|
|
*
|
|
* For example, if a function `myFunction` is protected by `onlyRole(SOME_ROLE)`, and
|
|
* if an address `x` has role `SOME_ROLE`, it would be able to call `myFunction` directly.
|
|
* A wallet or contract at the same address on another chain would however not be able
|
|
* to call this function. In order to do so, it would require to have the role
|
|
* `_crossChainRoleAlias(SOME_ROLE)`.
|
|
*
|
|
* This aliasing is required to protect against multiple contracts living at the same
|
|
* address on different chains but controlled by conflicting entities.
|
|
*
|
|
* _Available since v4.6._
|
|
*/
|
|
abstract contract AccessControlCrossChain is AccessControl, CrossChainEnabled {
|
|
bytes32 public constant CROSSCHAIN_ALIAS = keccak256("CROSSCHAIN_ALIAS");
|
|
|
|
/**
|
|
* @dev See {AccessControl-_checkRole}.
|
|
*/
|
|
function _checkRole(bytes32 role) internal view virtual override {
|
|
if (_isCrossChain()) {
|
|
_checkRole(_crossChainRoleAlias(role), _crossChainSender());
|
|
} else {
|
|
super._checkRole(role);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Returns the aliased role corresponding to `role`.
|
|
*/
|
|
function _crossChainRoleAlias(bytes32 role) internal pure virtual returns (bytes32) {
|
|
return role ^ CROSSCHAIN_ALIAS;
|
|
}
|
|
}
|