Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add polygon hook and ism #3038

Merged
merged 22 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
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
83 changes: 83 additions & 0 deletions solidity/contracts/hooks/PolygonPosHook.sol
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/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"
);
NOOMA-42 marked this conversation as resolved.
Show resolved Hide resolved
}

// ============ 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,
NOOMA-42 marked this conversation as resolved.
Show resolved Hide resolved
"PolygonPosHook: Fxchild not support msgValue"
NOOMA-42 marked this conversation as resolved.
Show resolved Hide resolved
);
_sendMessageToChild(payload);
}

// FIX: connect to mailbox, check how to do bidrectional
bytes public latestData;

function _processMessageFromChild(bytes memory data) internal override {
latestData = data;
}
NOOMA-42 marked this conversation as resolved.
Show resolved Hide resolved
}
66 changes: 66 additions & 0 deletions solidity/contracts/isms/hook/PolygonPosIsm.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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 ============

uint256 public latestStateId;
Fixed Show fixed Hide fixed
address public latestRootMessageSender;
Fixed Show fixed Hide fixed
bytes public latestData;
Fixed Show fixed Hide fixed

/* function sendMessageToRoot(bytes memory message) public {
_sendMessageToRoot(message);
} */
NOOMA-42 marked this conversation as resolved.
Show resolved Hide resolved

/**
* @notice Check if sender is authorized to message `verifyMessageId`.
*/
function _isAuthorized() internal view override returns (bool) {
return
_crossChainSender() == TypeCasts.bytes32ToAddress(authorizedHook);
}
}
1 change: 1 addition & 0 deletions solidity/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ verbosity = 4
[rpc_endpoints]
mainnet = "https://rpc.ankr.com/eth"
optimism = "https://rpc.ankr.com/optimism"
polygon = "https://rpc.ankr.com/polygon"
1 change: 1 addition & 0 deletions solidity/lib/fx-portal
Submodule fx-portal added at ebd046
1 change: 1 addition & 0 deletions solidity/remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
@eth-optimism=../node_modules/@eth-optimism
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
fx-portal/=lib/fx-portal/contracts/
Loading
Loading