* 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>
73 lines
2.5 KiB
Solidity
73 lines
2.5 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
// OpenZeppelin Contracts (last updated v4.6.0) (crosschain/polygon/CrossChainEnabledPolygonChild.sol)
|
|
|
|
pragma solidity ^0.8.4;
|
|
|
|
import "../CrossChainEnabled.sol";
|
|
import "../../security/ReentrancyGuard.sol";
|
|
import "../../utils/Address.sol";
|
|
import "../../vendor/polygon/IFxMessageProcessor.sol";
|
|
|
|
address constant DEFAULT_SENDER = 0x000000000000000000000000000000000000dEaD;
|
|
|
|
/**
|
|
* @dev [Polygon](https://polygon.technology/) specialization or the
|
|
* {CrossChainEnabled} abstraction the child side (polygon/mumbai).
|
|
*
|
|
* This version should only be deployed on child chain to process cross-chain
|
|
* messages originating from the parent chain.
|
|
*
|
|
* The fxChild contract is provided and maintained by the polygon team. You can
|
|
* find the address of this contract polygon and mumbai in
|
|
* [Polygon's Fx-Portal documentation](https://docs.polygon.technology/docs/develop/l1-l2-communication/fx-portal/#contract-addresses).
|
|
*
|
|
* _Available since v4.6._
|
|
*/
|
|
abstract contract CrossChainEnabledPolygonChild is IFxMessageProcessor, CrossChainEnabled, ReentrancyGuard {
|
|
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
address private immutable _fxChild;
|
|
address private _sender = DEFAULT_SENDER;
|
|
|
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
constructor(address fxChild) {
|
|
_fxChild = fxChild;
|
|
}
|
|
|
|
/**
|
|
* @dev see {CrossChainEnabled-_isCrossChain}
|
|
*/
|
|
function _isCrossChain() internal view virtual override returns (bool) {
|
|
return msg.sender == _fxChild;
|
|
}
|
|
|
|
/**
|
|
* @dev see {CrossChainEnabled-_crossChainSender}
|
|
*/
|
|
function _crossChainSender() internal view virtual override onlyCrossChain returns (address) {
|
|
return _sender;
|
|
}
|
|
|
|
/**
|
|
* @dev External entry point to receive and relay messages originating
|
|
* from the fxChild.
|
|
*
|
|
* Non-reentrancy is crucial to avoid a cross-chain call being able
|
|
* to impersonate anyone by just looping through this with user-defined
|
|
* arguments.
|
|
*
|
|
* Note: if _fxChild calls any other function that does a delegate-call,
|
|
* then security could be compromised.
|
|
*/
|
|
function processMessageFromRoot(
|
|
uint256, /* stateId */
|
|
address rootMessageSender,
|
|
bytes calldata data
|
|
) external override nonReentrant {
|
|
require(msg.sender == _fxChild, "unauthorized cross-chain relay");
|
|
|
|
_sender = rootMessageSender;
|
|
Address.functionDelegateCall(address(this), data, "crosschain execution failled");
|
|
_sender = DEFAULT_SENDER;
|
|
}
|
|
}
|