LibArbitrumL2.sol 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.8.0-rc.0) (crosschain/arbitrum/LibArbitrumL2.sol)
  3. pragma solidity ^0.8.4;
  4. import {IArbSys as ArbitrumL2_Bridge} from "../../vendor/arbitrum/IArbSys.sol";
  5. import "../errors.sol";
  6. /**
  7. * @dev Primitives for cross-chain aware contracts for
  8. * https://arbitrum.io/[Arbitrum].
  9. *
  10. * This version should only be used on L2 to process cross-chain messages
  11. * originating from L1. For the other side, use {LibArbitrumL1}.
  12. *
  13. * WARNING: There is currently a bug in Arbitrum that causes this contract to
  14. * fail to detect cross-chain calls when deployed behind a proxy. This will be
  15. * fixed when the network is upgraded to Arbitrum Nitro, currently scheduled for
  16. * August 31st 2022.
  17. */
  18. library LibArbitrumL2 {
  19. /**
  20. * @dev Returns whether the current function call is the result of a
  21. * cross-chain message relayed by `arbsys`.
  22. */
  23. address public constant ARBSYS = 0x0000000000000000000000000000000000000064;
  24. function isCrossChain(address arbsys) internal view returns (bool) {
  25. return ArbitrumL2_Bridge(arbsys).wasMyCallersAddressAliased();
  26. }
  27. /**
  28. * @dev Returns the address of the sender that triggered the current
  29. * cross-chain message through `arbsys`.
  30. *
  31. * NOTE: {isCrossChain} should be checked before trying to recover the
  32. * sender, as it will revert with `NotCrossChainCall` if the current
  33. * function call is not the result of a cross-chain message.
  34. */
  35. function crossChainSender(address arbsys) internal view returns (address) {
  36. if (!isCrossChain(arbsys)) revert NotCrossChainCall();
  37. return ArbitrumL2_Bridge(arbsys).myCallersAddressWithoutAliasing();
  38. }
  39. }