|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +/* |
| 4 | + * Copyright 2019-2021, Offchain Labs, Inc. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +pragma solidity >=0.7.0; |
| 20 | + |
| 21 | +library AddressAliasHelper { |
| 22 | + uint160 constant offset = uint160(0x1111000000000000000000000000000000001111); |
| 23 | + |
| 24 | + /// @notice Utility function that converts the address in the L1 that submitted a tx to |
| 25 | + /// the inbox to the msg.sender viewed in the L2 |
| 26 | + /// @param l1Address the address in the L1 that triggered the tx to L2 |
| 27 | + /// @return l2Address L2 address as viewed in msg.sender |
| 28 | + function applyL1ToL2Alias(address l1Address) internal pure returns (address l2Address) { |
| 29 | + l2Address = address(uint160(l1Address) + offset); |
| 30 | + } |
| 31 | + |
| 32 | + /// @notice Utility function that converts the msg.sender viewed in the L2 to the |
| 33 | + /// address in the L1 that submitted a tx to the inbox |
| 34 | + /// @param l2Address L2 address as viewed in msg.sender |
| 35 | + /// @return l1Address the address in the L1 that triggered the tx to L2 |
| 36 | + function undoL1ToL2Alias(address l2Address) internal pure returns (address l1Address) { |
| 37 | + l1Address = address(uint160(l2Address) - offset); |
| 38 | + } |
| 39 | +} |
0 commit comments