CrossChainEnabled.sol 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.4;
  3. import "./errors.sol";
  4. /**
  5. * @dev Provides information for building cross-chain aware contracts. This
  6. * abstract contract provides accessors and modifiers to control the execution
  7. * flow when receiving cross-chain messages.
  8. *
  9. * Actual implementations of cross-chain aware contracts, which are based on
  10. * this abstraction, will have to inherit from a bridge-specific
  11. * specialization. Such specializations are provided under
  12. * `crosschain/<chain>/CrossChainEnabled<chain>.sol`.
  13. *
  14. * _Available since v4.6._
  15. */
  16. abstract contract CrossChainEnabled {
  17. /**
  18. * @dev Throws if the current function call is not the result of a
  19. * cross-chain execution.
  20. */
  21. modifier onlyCrossChain() {
  22. if (!_isCrossChain()) revert NotCrossChainCall();
  23. _;
  24. }
  25. /**
  26. * @dev Throws if the current function call is not the result of a
  27. * cross-chain execution initiated by `account`.
  28. */
  29. modifier onlyCrossChainSender(address expected) {
  30. address actual = _crossChainSender();
  31. if (expected != actual) revert InvalidCrossChainSender(actual, expected);
  32. _;
  33. }
  34. /**
  35. * @dev Returns whether the current function call is the result of a
  36. * cross-chain message.
  37. */
  38. function _isCrossChain() internal view virtual returns (bool);
  39. /**
  40. * @dev Returns the address of the sender of the cross-chain message that
  41. * triggered the current function call.
  42. *
  43. * IMPORTANT: Should revert with `NotCrossChainCall` if the current function
  44. * call is not the result of a cross-chain message.
  45. */
  46. function _crossChainSender() internal view virtual returns (address);
  47. }