-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes address alias import in scroll sequencer uptime feed
- Loading branch information
1 parent
7b671f7
commit a06acfc
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
29 changes: 29 additions & 0 deletions
29
contracts/src/v0.8/vendor/@scroll-tech/contracts/src/libraries/common/AddressAliasHelper.sol
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.16; | ||
|
||
// @source: https://github.com/scroll-tech/scroll/blob/develop/contracts/src/libraries/common/AddressAliasHelper.sol | ||
library AddressAliasHelper { | ||
/// @dev The offset added to the address in L1. | ||
uint160 internal constant OFFSET = uint160(0x1111000000000000000000000000000000001111); | ||
|
||
/// @notice Utility function that converts the address in the L1 that submitted a tx to | ||
/// the inbox to the msg.sender viewed in the L2 | ||
/// @param l1Address the address in the L1 that triggered the tx to L2 | ||
/// @return l2Address L2 address as viewed in msg.sender | ||
function applyL1ToL2Alias(address l1Address) internal pure returns (address l2Address) { | ||
unchecked { | ||
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) { | ||
unchecked { | ||
l1Address = address(uint160(l2Address) - OFFSET); | ||
} | ||
} | ||
} |