Created
August 31, 2021 15:29
-
-
Save fredlacs/8406252b6922d1e17e302914eba69924 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.11+commit.5ef660b1.js&optimize=false&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: Apache-2.0 | |
| pragma solidity ^0.6.11; | |
| library AddressAliasHelper { | |
| uint160 constant offset = uint160(0x1111000000000000000000000000000000001111); | |
| /// @notice Utility function that converts the msg.sender viewed in the L2 to the | |
| /// address in the L1 that submitted a tx to the inbox | |
| /// @param l1Address L2 address as viewed in msg.sender | |
| /// @return l2Address the address in the L1 that triggered the tx to L2 | |
| function applyL1ToL2Alias(address l1Address) internal pure returns (address l2Address) { | |
| l2Address = address(uint160(l1Address) + offset); | |
| } | |
| /// @notice Utility function that converts the msg.sender viewed in the L2 to the | |
| /// address in the L1 that submitted a tx to the inbox | |
| /// @param l2Address L2 address as viewed in msg.sender | |
| /// @return l1Address the address in the L1 that triggered the tx to L2 | |
| function undoL1ToL2Alias(address l2Address) internal pure returns (address l1Address) { | |
| l1Address = address(uint160(l2Address) - offset); | |
| } | |
| } | |
| contract Test { | |
| function getValue() external view returns(address) { | |
| return AddressAliasHelper.applyL1ToL2Alias(address(0xAEb7fFf13Bf3b10AE176dE39eE468aE03DC8109f)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment