-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: forwarders for AVM and OVM networks (#625)
* feat: forwarders for AVM and OVM networks Signed-off-by: bennett <bennett@umaproject.org> --------- Signed-off-by: bennett <bennett@umaproject.org> Co-authored-by: nicholaspai <9457025+nicholaspai@users.noreply.github.com> Co-authored-by: Matt Rice <matthewcrice32@gmail.com>
- Loading branch information
1 parent
abe2f7f
commit 3d61c1b
Showing
5 changed files
with
80 additions
and
22 deletions.
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
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
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,28 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.0; | ||
|
||
import { ForwarderBase } from "./ForwarderBase.sol"; | ||
import { CrossDomainAddressUtils } from "../libraries/CrossDomainAddressUtils.sol"; | ||
|
||
/** | ||
* @title Arbitrum_Forwarder | ||
* @notice This contract expects to receive messages and tokens from the hub pool on L1 and forwards messages to a spoke pool on L3. | ||
* It rejects messages which do not originate from a cross domain admin, which is set as the hub pool. | ||
* @custom:security-contact bugs@across.to | ||
*/ | ||
contract Arbitrum_Forwarder is ForwarderBase { | ||
// On Arbitrum, L1 msg.senders are derived by aliasing a L1 address. | ||
modifier onlyFromCrossDomainAdmin() { | ||
require(msg.sender == CrossDomainAddressUtils.applyL1ToL2Alias(crossDomainAdmin), "ONLY_COUNTERPART_GATEWAY"); | ||
_; | ||
} | ||
|
||
/** | ||
* @notice Constructs an Arbitrum-specific forwarder contract. | ||
* @dev Since this is a proxy contract, we only set immutable variables in the constructor, and leave everything else to be initialized. | ||
* This includes variables like the cross domain admin. | ||
*/ | ||
constructor() ForwarderBase() {} | ||
|
||
function _requireAdminSender() internal override onlyFromCrossDomainAdmin {} | ||
} |
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,31 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.0; | ||
|
||
import { ForwarderBase } from "./ForwarderBase.sol"; | ||
import { LibOptimismUpgradeable } from "@openzeppelin/contracts-upgradeable/crosschain/optimism/LibOptimismUpgradeable.sol"; | ||
import { Lib_PredeployAddresses } from "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol"; | ||
|
||
/** | ||
* @title Ovm_Forwarder | ||
* @notice This contract expects to receive messages and tokens from the hub pool on L1 and forwards messages to a spoke pool on L3. | ||
* It rejects messages which do not originate from a cross domain admin, which is set as the hub pool. | ||
* @dev This forwarder assumes that the cross domain messenger predeploy contract is set to the same contract as the standard OpStack predeploy. | ||
* (0x4200000000000000000000000000000000000007). This is because in order to determine the L1 msg.sender of a cross-chain message, we must | ||
* query information from that contract. | ||
* @custom:security-contact bugs@across.to | ||
*/ | ||
contract Ovm_Forwarder is ForwarderBase { | ||
// Address of the cross domain messenger contract. | ||
address public constant MESSENGER = Lib_PredeployAddresses.L2_CROSS_DOMAIN_MESSENGER; | ||
|
||
error NotCrossDomainAdmin(); | ||
|
||
/** | ||
@notice Constructs an Ovm specific forwarder contract. | ||
*/ | ||
constructor() ForwarderBase() {} | ||
|
||
function _requireAdminSender() internal view override { | ||
if (LibOptimismUpgradeable.crossChainSender(MESSENGER) != crossDomainAdmin) revert NotCrossDomainAdmin(); | ||
} | ||
} |
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,17 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @title AddressUtils | ||
* @notice This library contains internal functions for manipulating addresses. | ||
*/ | ||
library CrossDomainAddressUtils { | ||
// L1 addresses are transformed during l1->l2 calls. | ||
// This cannot be pulled directly from Arbitrum contracts because their contracts are not 0.8.X compatible and | ||
// this operation takes advantage of overflows, whose behavior changed in 0.8.0. | ||
function applyL1ToL2Alias(address l1Address) internal pure returns (address l2Address) { | ||
unchecked { | ||
l2Address = address(uint160(l1Address) + uint160(0x1111000000000000000000000000000000001111)); | ||
} | ||
} | ||
} |