LibArbitrumL1.sol 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.8.0-rc.2) (crosschain/arbitrum/LibArbitrumL1.sol)
  3. pragma solidity ^0.8.4;
  4. import {IBridge as ArbitrumL1_Bridge} from "../../vendor/arbitrum/IBridge.sol";
  5. import {IOutbox as ArbitrumL1_Outbox} from "../../vendor/arbitrum/IOutbox.sol";
  6. import "../errors.sol";
  7. /**
  8. * @dev Primitives for cross-chain aware contracts for
  9. * https://arbitrum.io/[Arbitrum].
  10. *
  11. * This version should only be used on L1 to process cross-chain messages
  12. * originating from L2. For the other side, use {LibArbitrumL2}.
  13. */
  14. library LibArbitrumL1 {
  15. /**
  16. * @dev Returns whether the current function call is the result of a
  17. * cross-chain message relayed by the `bridge`.
  18. */
  19. function isCrossChain(address bridge) internal view returns (bool) {
  20. return msg.sender == bridge;
  21. }
  22. /**
  23. * @dev Returns the address of the sender that triggered the current
  24. * cross-chain message through the `bridge`.
  25. *
  26. * NOTE: {isCrossChain} should be checked before trying to recover the
  27. * sender, as it will revert with `NotCrossChainCall` if the current
  28. * function call is not the result of a cross-chain message.
  29. */
  30. function crossChainSender(address bridge) internal view returns (address) {
  31. if (!isCrossChain(bridge)) revert NotCrossChainCall();
  32. address sender = ArbitrumL1_Outbox(ArbitrumL1_Bridge(bridge).activeOutbox()).l2ToL1Sender();
  33. require(sender != address(0), "LibArbitrumL1: system messages without sender");
  34. return sender;
  35. }
  36. }