Skip to content

Commit

Permalink
Update multisig ISMs for merkle hooks (#2722)
Browse files Browse the repository at this point in the history
  • Loading branch information
yorhodes authored Sep 13, 2023
1 parent 7dd2190 commit f9f74d6
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 1,272 deletions.
29 changes: 18 additions & 11 deletions solidity/contracts/isms/multisig/AbstractMerkleRootMultisigIsm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import {CheckpointLib} from "../../libs/CheckpointLib.sol";
* @dev May be adapted in future to support batch message verification against a single root.
*/
abstract contract AbstractMerkleRootMultisigIsm is AbstractMultisigIsm {
using MerkleRootMultisigIsmMetadata for bytes;
using Message for bytes;

// ============ Constants ============

// solhint-disable-next-line const-name-snakecase
Expand All @@ -38,20 +41,24 @@ abstract contract AbstractMerkleRootMultisigIsm is AbstractMultisigIsm {
override
returns (bytes32)
{
require(
_metadata.messageIndex() <= _metadata.signedIndex(),
"Invalid merkle index metadata"
);
// We verify a merkle proof of (messageId, index) I to compute root J
bytes32 _root = MerkleLib.branchRoot(
Message.id(_message),
MerkleRootMultisigIsmMetadata.proof(_metadata),
Message.nonce(_message)
bytes32 _signedRoot = MerkleLib.branchRoot(
_message.id(),
_metadata.proof(),
_metadata.messageIndex()
);
// We provide (messageId, index) J in metadata for digest derivation
return
CheckpointLib.digest(
Message.origin(_message),
MerkleRootMultisigIsmMetadata.originMailbox(_metadata),
_root,
MerkleRootMultisigIsmMetadata.index(_metadata),
MerkleRootMultisigIsmMetadata.messageId(_metadata)
_message.origin(),
_metadata.originMerkleTreeHook(),
_signedRoot,
_metadata.signedIndex(),
_metadata.signedMessageId()
);
}

Expand All @@ -63,8 +70,8 @@ abstract contract AbstractMerkleRootMultisigIsm is AbstractMultisigIsm {
pure
virtual
override
returns (bytes memory signature)
returns (bytes calldata)
{
return MerkleRootMultisigIsmMetadata.signatureAt(_metadata, _index);
return _metadata.signatureAt(_index);
}
}
17 changes: 10 additions & 7 deletions solidity/contracts/isms/multisig/AbstractMessageIdMultisigIsm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {CheckpointLib} from "../../libs/CheckpointLib.sol";
* This abstract contract can be customized to change the `validatorsAndThreshold()` (static or dynamic).
*/
abstract contract AbstractMessageIdMultisigIsm is AbstractMultisigIsm {
using Message for bytes;
using MessageIdMultisigIsmMetadata for bytes;

// ============ Constants ============

// solhint-disable-next-line const-name-snakecase
Expand All @@ -36,11 +39,11 @@ abstract contract AbstractMessageIdMultisigIsm is AbstractMultisigIsm {
{
return
CheckpointLib.digest(
Message.origin(_message),
MessageIdMultisigIsmMetadata.originMailbox(_metadata),
MessageIdMultisigIsmMetadata.root(_metadata),
Message.nonce(_message),
Message.id(_message)
_message.origin(),
_metadata.originMerkleTreeHook(),
_metadata.root(),
_metadata.index(),
_message.id()
);
}

Expand All @@ -52,8 +55,8 @@ abstract contract AbstractMessageIdMultisigIsm is AbstractMultisigIsm {
pure
virtual
override
returns (bytes memory)
returns (bytes calldata)
{
return MessageIdMultisigIsmMetadata.signatureAt(_metadata, _index);
return _metadata.signatureAt(_index);
}
}
2 changes: 1 addition & 1 deletion solidity/contracts/isms/multisig/AbstractMultisigIsm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ abstract contract AbstractMultisigIsm is IMultisigIsm {
internal
pure
virtual
returns (bytes memory);
returns (bytes calldata);

// ============ Public Functions ============

Expand Down
Loading

0 comments on commit f9f74d6

Please sign in to comment.