-
Notifications
You must be signed in to change notification settings - Fork 422
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
feat: Polygon ZKevm v2 hook and ism #4547
base: main
Are you sure you want to change the base?
Conversation
|
* @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 { |
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.
can you inherit from AbstractMessageIdAuthHook here, it'll mean less code duplication?
bytes calldata, | ||
bytes calldata | ||
) external pure override returns (uint256) { | ||
return 0; |
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.
But I imagine there's still some additional overhead for the relayer to submit the tx on the destination chain. You can follow using a childHook which is effectively an IGP:
metadata.msgValue(0) + childHook.quoteDispatch(metadata, message); |
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.
It's a good start, take a look at the comments. It'll be easier to separate this into two PRs for v1 and v2.
); | ||
bytes32 messageId = message.id(); | ||
|
||
zkEvmBridge.bridgeMessage{value: msg.value}( |
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.
Only send the metadata.msgValue(0) and refund the rest
* @notice Message hook to inform the {Polygon zkEVM chain Ism} of messages published through | ||
* the native Polygon zkEVM bridge bridge. | ||
*/ | ||
contract PolygonZkevmV2Hook is IPostDispatchHook, MailboxClient { |
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.
inherit from AbstractMessageIdAuthHook here instead too
"PolygonzkEVMv2Hook: invalid destination domain" | ||
); | ||
require( | ||
_zkEvmBridgeDestinationNetId <= 1, |
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.
this can only be 0 or 1 then?
bytes calldata | ||
) external view override returns (uint256) { | ||
return | ||
interchainGasPaymaster.quoteGasPayment( |
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.
make this child hook
bytes calldata _message | ||
) external payable override { | ||
bytes32 messageId = keccak256(_message); | ||
uint256 gasPayment = interchainGasPaymaster.quoteGasPayment( |
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.
childHook.quoteDispatch()
VERIFIED_MASK_INDEX | ||
); | ||
if (_msgValue > 0) { | ||
verifiedMessages[messageId] -= _msgValue; |
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.
send extra msgValue (via the metadata) so we don't have leftover here
* @dev off-chain verification information for a given message. | ||
* @param _message The message for which off-chain verification information is requested. | ||
*/ | ||
function getOffchainVerifyInfo( |
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.
why do we need CCIP here, the relayer will be calling the verify function, no?
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.
maybe helpful to make a quick mermaid diagram.
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.
@curlypoint did make a diagram for v1, v2 also follows similar flow.
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.
yeah, that's something that was needed to be discussed as bridge needs to generate a proof to claim. the ccip call was for the hyperlane relayer to get that proof using PolygonZKevm api (tho that does not follow the ccip spec.
* @notice Polygon zkEVM chain Ism that uses the Polygon zkEVM bridge to verify messages | ||
*/ | ||
contract PolygonZkevmV2Ism is | ||
ICcipReadIsm, |
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.
similar comments to v1
* @inheritdoc AbstractMessageIdAuthorizedIsm | ||
*/ | ||
function _isAuthorized() internal view override returns (bool) { | ||
bytes32 originSender = abi.decode(msg.data[4:], (bytes32)); |
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.
don't we need to access control msg.sender since msg.data[4:] can be arbitrarily set by the caller?
@@ -0,0 +1,25 @@ | |||
// SPDX-License-Identifier: MIT OR Apache-2.0 |
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.
we already have TestInterchainGasPaymaster
Description
This PR adds a hook and ISM contract for Polygon's zkEVM v2 bridge.
The contracts tap into the Polygon zkEVM bridge to ensure cross-chain messages come from a trusted source. This works by using the zkEVM bridge's exit nodes, which handle verifying the message integrity.
This PR also includes code from PR #3136
PR for docs : PR 40
Drive-by changes
None
Related issues
Fixes #2848
Backward compatibility
Yes