-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Description - Add native polygon bridge hook and isms ### Related issues - Fixes #2847 - Documented with hyperlane-xyz/v3-docs#31 ### Backward compatibility Yes ### Testing Unit Tests --------- Co-authored-by: NOOMA-42 <[email protected]>
- Loading branch information
Showing
9 changed files
with
534 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "solidity/lib/forge-std"] | ||
path = solidity/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "solidity/lib/fx-portal"] | ||
path = solidity/lib/fx-portal | ||
url = https://github.com/0xPolygon/fx-portal |
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,83 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity >=0.8.0; | ||
|
||
/*@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@ HYPERLANE @@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@*/ | ||
|
||
// ============ Internal Imports ============ | ||
import {AbstractMessageIdAuthHook} from "./libs/AbstractMessageIdAuthHook.sol"; | ||
import {StandardHookMetadata} from "./libs/StandardHookMetadata.sol"; | ||
import {TypeCasts} from "../libs/TypeCasts.sol"; | ||
import {Message} from "../libs/Message.sol"; | ||
import {IPostDispatchHook} from "../interfaces/hooks/IPostDispatchHook.sol"; | ||
|
||
// ============ External Imports ============ | ||
import {FxBaseRootTunnel} from "fx-portal/contracts/tunnel/FxBaseRootTunnel.sol"; | ||
import {Address} from "@openzeppelin/contracts/utils/Address.sol"; | ||
|
||
/** | ||
* @title PolygonPosHook | ||
* @notice Message hook to inform the PolygonPosIsm of messages published through | ||
* the native PoS bridge. | ||
*/ | ||
contract PolygonPosHook is AbstractMessageIdAuthHook, FxBaseRootTunnel { | ||
using StandardHookMetadata for bytes; | ||
|
||
// ============ Constructor ============ | ||
|
||
constructor( | ||
address _mailbox, | ||
uint32 _destinationDomain, | ||
bytes32 _ism, | ||
address _cpManager, | ||
address _fxRoot | ||
) | ||
AbstractMessageIdAuthHook(_mailbox, _destinationDomain, _ism) | ||
FxBaseRootTunnel(_cpManager, _fxRoot) | ||
{ | ||
require( | ||
Address.isContract(_cpManager), | ||
"PolygonPosHook: invalid cpManager contract" | ||
); | ||
require( | ||
Address.isContract(_fxRoot), | ||
"PolygonPosHook: invalid fxRoot contract" | ||
); | ||
} | ||
|
||
// ============ Internal functions ============ | ||
function _quoteDispatch( | ||
bytes calldata, | ||
bytes calldata | ||
) internal pure override returns (uint256) { | ||
return 0; | ||
} | ||
|
||
/// @inheritdoc AbstractMessageIdAuthHook | ||
function _sendMessageId( | ||
bytes calldata metadata, | ||
bytes memory payload | ||
) internal override { | ||
require( | ||
metadata.msgValue(0) == 0, | ||
"PolygonPosHook: does not support msgValue" | ||
); | ||
require(msg.value == 0, "PolygonPosHook: does not support msgValue"); | ||
_sendMessageToChild(payload); | ||
} | ||
|
||
bytes public latestData; | ||
|
||
function _processMessageFromChild(bytes memory data) internal override { | ||
latestData = data; | ||
} | ||
} |
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,58 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity >=0.8.0; | ||
|
||
/*@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@ HYPERLANE @@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@*/ | ||
|
||
// ============ Internal Imports ============ | ||
|
||
import {IInterchainSecurityModule} from "../../interfaces/IInterchainSecurityModule.sol"; | ||
import {Message} from "../../libs/Message.sol"; | ||
import {TypeCasts} from "../../libs/TypeCasts.sol"; | ||
import {AbstractMessageIdAuthorizedIsm} from "./AbstractMessageIdAuthorizedIsm.sol"; | ||
|
||
// ============ External Imports ============ | ||
import {CrossChainEnabledPolygonChild} from "@openzeppelin/contracts/crosschain/polygon/CrossChainEnabledPolygonChild.sol"; | ||
import {Address} from "@openzeppelin/contracts/utils/Address.sol"; | ||
|
||
/** | ||
* @title PolygonPosIsm | ||
* @notice Uses the native Polygon Pos Fx Portal Bridge to verify interchain messages. | ||
*/ | ||
contract PolygonPosIsm is | ||
CrossChainEnabledPolygonChild, | ||
AbstractMessageIdAuthorizedIsm | ||
{ | ||
// ============ Constants ============ | ||
|
||
uint8 public constant moduleType = | ||
uint8(IInterchainSecurityModule.Types.NULL); | ||
|
||
// ============ Constructor ============ | ||
|
||
constructor(address _fxChild) CrossChainEnabledPolygonChild(_fxChild) { | ||
require( | ||
Address.isContract(_fxChild), | ||
"PolygonPosIsm: invalid FxChild contract" | ||
); | ||
} | ||
|
||
// ============ Internal function ============ | ||
|
||
/** | ||
* @notice Check if sender is authorized to message `verifyMessageId`. | ||
*/ | ||
function _isAuthorized() internal view override returns (bool) { | ||
return | ||
_crossChainSender() == TypeCasts.bytes32ToAddress(authorizedHook); | ||
} | ||
} |
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
Oops, something went wrong.