LibArbitrumL1.sol 1.6 KB

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