-
Notifications
You must be signed in to change notification settings - Fork 369
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
Polygon ZKevm hook and ism #3136
Open
curlypoint
wants to merge
11
commits into
hyperlane-xyz:main
Choose a base branch
from
curlypoint:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+765
−2
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
67478f7
WIP : Polygon ZKevm hook and ism
curlypoint 5926110
Merge branch 'hyperlane-xyz:main' into main
curlypoint bc02510
WIP : Use CCIP protocol to fetch proofs
curlypoint b5bb215
fixes for hook
curlypoint 959b819
Add PolygonZkEVM bridge message receiver interface, pass message id i…
curlypoint 6f89d45
TODO: test cases
curlypoint 47f90ea
add some docs
curlypoint 3b85f3d
Try testing
curlypoint ab9a927
revert extra changes to abstractmessageidautharizedism
curlypoint ebc73a6
Fix: requested changes
curlypoint c4130b5
add test, add check for messageId in verify ism (ran into stack too d…
curlypoint File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity >=0.8.0; | ||
|
||
/*@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@ HYPERLANE @@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@*/ | ||
|
||
// ============ Internal Imports ============ | ||
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 {Address} from "@openzeppelin/contracts/utils/Address.sol"; | ||
|
||
import {IPolygonZkEVMBridge} from "../interfaces/polygonzkevm/IPolygonZkEVMBridge.sol"; | ||
import {MailboxClient} from "../client/MailboxClient.sol"; | ||
|
||
/** | ||
* @title PolygonZkevmHook | ||
* @notice Message hook to inform the {Polygon zkEVM chain Ism} of messages published through | ||
* the native Polygon zkEVM bridge bridge. | ||
*/ | ||
contract PolygonZkevmHook is IPostDispatchHook, MailboxClient { | ||
using StandardHookMetadata for bytes; | ||
using Message for bytes; | ||
using TypeCasts for bytes32; | ||
|
||
// ============ Immutable Variables ============ | ||
IPolygonZkEVMBridge public immutable zkEvmBridge; | ||
|
||
// left-padded address for ISM to verify messages | ||
address public immutable ism; | ||
// Domain of chain on which the ISM is deployed | ||
uint32 public immutable destinationDomain; | ||
// Polygon ZkevmBridge uses networkId 0 for Mainnet and 1 for rollup | ||
uint32 public immutable zkEvmBridgeDestinationNetId; | ||
|
||
constructor( | ||
address _mailbox, | ||
uint32 _destinationDomain, | ||
address _ism, | ||
address _zkEvmBridge, | ||
uint32 _zkEvmBridgeDestinationNetId | ||
) MailboxClient(_mailbox) { | ||
require( | ||
Address.isContract(_zkEvmBridge), | ||
"PolygonzkEVMHook: invalid PolygonZkEVMBridge contract" | ||
); | ||
require( | ||
_destinationDomain != 0, | ||
"PolygonzkEVMHook: invalid destination domain" | ||
); | ||
require( | ||
_zkEvmBridgeDestinationNetId <= 1, | ||
"PolygonZkevmIsm: invalid ZkEVMBridge destination network id" | ||
); | ||
ism = _ism; | ||
destinationDomain = _destinationDomain; | ||
zkEvmBridge = IPolygonZkEVMBridge(_zkEvmBridge); | ||
zkEvmBridgeDestinationNetId = uint8(_zkEvmBridgeDestinationNetId); | ||
} | ||
|
||
/// @inheritdoc IPostDispatchHook | ||
function supportsMetadata( | ||
bytes calldata | ||
) public pure virtual override returns (bool) { | ||
return true; | ||
} | ||
|
||
/// @dev This value is hardcoded to 0 because the Polygon zkEVM bridge does not support fee quotes | ||
function quoteDispatch( | ||
bytes calldata, | ||
bytes calldata | ||
) external pure override returns (uint256) { | ||
return 0; | ||
} | ||
|
||
/// @inheritdoc IPostDispatchHook | ||
function postDispatch( | ||
bytes calldata metadata, | ||
bytes calldata message | ||
) external payable override { | ||
require( | ||
metadata.msgValue(0) < 2 ** 255, | ||
"PolygonzkEVMHook: msgValue must be less than 2 ** 255" | ||
); | ||
bytes32 messageId = message.id(); | ||
|
||
zkEvmBridge.bridgeMessage{value: msg.value}( | ||
zkEvmBridgeDestinationNetId, | ||
address(ism), | ||
true, | ||
curlypoint marked this conversation as resolved.
Show resolved
Hide resolved
|
||
abi.encodePacked(messageId) | ||
); | ||
} | ||
|
||
function hookType() external view override returns (uint8) {} | ||
} |
14 changes: 14 additions & 0 deletions
14
solidity/contracts/interfaces/polygonZkevm/IBridgeMessageReceiver.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,14 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
|
||
pragma solidity >=0.8.0; | ||
|
||
/** | ||
* @dev Define interface for PolygonZkEVM Bridge message receiver | ||
*/ | ||
interface IBridgeMessageReceiver { | ||
function onMessageReceived( | ||
address originAddress, | ||
uint32 originNetwork, | ||
bytes memory data | ||
) external payable; | ||
} |
118 changes: 118 additions & 0 deletions
118
solidity/contracts/interfaces/polygonZkevm/IPolygonZkEVMBridge.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,118 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
interface IPolygonZkEVMBridge { | ||
/** | ||
* @dev Thrown when sender is not the PolygonZkEVM address | ||
*/ | ||
error OnlyPolygonZkEVM(); | ||
|
||
/** | ||
* @dev Thrown when the destination network is invalid | ||
*/ | ||
error DestinationNetworkInvalid(); | ||
|
||
/** | ||
* @dev Thrown when the amount does not match msg.value | ||
*/ | ||
error AmountDoesNotMatchMsgValue(); | ||
|
||
/** | ||
* @dev Thrown when user is bridging tokens and is also sending a value | ||
*/ | ||
error MsgValueNotZero(); | ||
|
||
/** | ||
* @dev Thrown when the Ether transfer on claimAsset fails | ||
*/ | ||
error EtherTransferFailed(); | ||
|
||
/** | ||
* @dev Thrown when the message transaction on claimMessage fails | ||
*/ | ||
error MessageFailed(); | ||
|
||
/** | ||
* @dev Thrown when the global exit root does not exist | ||
*/ | ||
error GlobalExitRootInvalid(); | ||
|
||
/** | ||
* @dev Thrown when the smt proof does not match | ||
*/ | ||
error InvalidSmtProof(); | ||
|
||
/** | ||
* @dev Thrown when an index is already claimed | ||
*/ | ||
error AlreadyClaimed(); | ||
|
||
/** | ||
* @dev Thrown when the owner of permit does not match the sender | ||
*/ | ||
error NotValidOwner(); | ||
|
||
/** | ||
* @dev Thrown when the spender of the permit does not match this contract address | ||
*/ | ||
error NotValidSpender(); | ||
|
||
/** | ||
* @dev Thrown when the amount of the permit does not match | ||
*/ | ||
error NotValidAmount(); | ||
|
||
/** | ||
* @dev Thrown when the permit data contains an invalid signature | ||
*/ | ||
error NotValidSignature(); | ||
|
||
function bridgeAsset( | ||
uint32 destinationNetwork, | ||
address destinationAddress, | ||
uint256 amount, | ||
address token, | ||
bool forceUpdateGlobalExitRoot, | ||
bytes calldata permitData | ||
) external payable; | ||
|
||
function bridgeMessage( | ||
uint32 destinationNetwork, | ||
address destinationAddress, | ||
bool forceUpdateGlobalExitRoot, | ||
bytes calldata metadata | ||
) external payable; | ||
|
||
function claimAsset( | ||
bytes32[32] calldata smtProof, | ||
uint32 index, | ||
bytes32 mainnetExitRoot, | ||
bytes32 rollupExitRoot, | ||
uint32 originNetwork, | ||
address originTokenAddress, | ||
uint32 destinationNetwork, | ||
address destinationAddress, | ||
uint256 amount, | ||
bytes calldata metadata | ||
) external; | ||
|
||
function claimMessage( | ||
bytes32[32] calldata smtProof, | ||
uint32 index, | ||
bytes32 mainnetExitRoot, | ||
bytes32 rollupExitRoot, | ||
uint32 originNetwork, | ||
address originAddress, | ||
uint32 destinationNetwork, | ||
address destinationAddress, | ||
uint256 amount, | ||
bytes calldata metadata | ||
) external; | ||
|
||
function updateGlobalExitRoot() external; | ||
|
||
function activateEmergencyState() external; | ||
|
||
function deactivateEmergencyState() external; | ||
} |
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 |
---|---|---|
|
@@ -74,7 +74,7 @@ abstract contract AbstractMessageIdAuthorizedIsm is | |
bytes calldata, | ||
/*_metadata*/ | ||
bytes calldata message | ||
) external returns (bool) { | ||
) external virtual returns (bool) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needed to modify this function as relayer caller verify after the CCIP call |
||
bytes32 messageId = message.id(); | ||
|
||
// check for the first bit (used for verification) | ||
|
@@ -99,7 +99,7 @@ abstract contract AbstractMessageIdAuthorizedIsm is | |
* @dev Only callable by the authorized hook. | ||
* @param messageId Hyperlane Id of the message. | ||
*/ | ||
function verifyMessageId(bytes32 messageId) external payable virtual { | ||
function verifyMessageId(bytes32 messageId) public payable virtual { | ||
require( | ||
_isAuthorized(), | ||
"AbstractMessageIdAuthorizedIsm: sender is not the hook" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how are fees calculated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users have to call the claim function on destination chain, we're calling that in
verify(metadata,message)
call,after fetching the smt proof needed using CCIP.