From a06acfc3828393215c4fc413ed02f1abd9f4d692 Mon Sep 17 00:00:00 2001 From: Chris De Leon Date: Fri, 16 Feb 2024 11:41:36 -0800 Subject: [PATCH] fixes address alias import in scroll sequencer uptime feed --- .../dev/scroll/ScrollSequencerUptimeFeed.sol | 2 +- .../libraries/common/AddressAliasHelper.sol | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 contracts/src/v0.8/vendor/@scroll-tech/contracts/src/libraries/common/AddressAliasHelper.sol diff --git a/contracts/src/v0.8/l2ep/dev/scroll/ScrollSequencerUptimeFeed.sol b/contracts/src/v0.8/l2ep/dev/scroll/ScrollSequencerUptimeFeed.sol index 5f503a2ab72..4c2d06eaa89 100644 --- a/contracts/src/v0.8/l2ep/dev/scroll/ScrollSequencerUptimeFeed.sol +++ b/contracts/src/v0.8/l2ep/dev/scroll/ScrollSequencerUptimeFeed.sol @@ -9,7 +9,7 @@ import {TypeAndVersionInterface} from "../../../interfaces/TypeAndVersionInterfa import {SimpleReadAccessController} from "../../../shared/access/SimpleReadAccessController.sol"; -import {AddressAliasHelper} from "../../../vendor/arb-bridge-eth/v0.8.0-custom/contracts/libraries/AddressAliasHelper.sol"; +import {AddressAliasHelper} from "../../../vendor/@scroll-tech/contracts/src/libraries/common/AddressAliasHelper.sol"; import {IL2ScrollMessenger} from "@scroll-tech/contracts/L2/IL2ScrollMessenger.sol"; /// @title ScrollSequencerUptimeFeed - L2 sequencer uptime status aggregator diff --git a/contracts/src/v0.8/vendor/@scroll-tech/contracts/src/libraries/common/AddressAliasHelper.sol b/contracts/src/v0.8/vendor/@scroll-tech/contracts/src/libraries/common/AddressAliasHelper.sol new file mode 100644 index 00000000000..474994333f6 --- /dev/null +++ b/contracts/src/v0.8/vendor/@scroll-tech/contracts/src/libraries/common/AddressAliasHelper.sol @@ -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); + } + } +}