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

fix: recipient rate limited ISM #4636

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/breezy-toys-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/core': minor
---

fix: constrain rate limited ISM to a single message recipient
23 changes: 19 additions & 4 deletions solidity/contracts/isms/warp-route/RateLimitedIsm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using Message for bytes;
using TokenMessage for bytes;

address public immutable recipient;

Check notice

Code scanning / Olympix Integrated Security

Some state variables are not being fuzzed in test functions, potentially leaving vulnerabilities unexplored. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/unfuzzed-variables Low

Some state variables are not being fuzzed in test functions, potentially leaving vulnerabilities unexplored. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/unfuzzed-variables

mapping(bytes32 messageId => bool validated) public messageValidated;

modifier validateMessageOnce(bytes calldata _message) {
Expand All @@ -25,14 +27,22 @@
_;
}

modifier onlyRecipient(bytes calldata _message) {
require(_message.recipientAddress() == recipient, "InvalidRecipient");
_;
}

constructor(
address _mailbox,
uint256 _maxCapacity
) MailboxClient(_mailbox) RateLimited(_maxCapacity) {}
uint256 _maxCapacity,

Check notice

Code scanning / Olympix Integrated Security

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor Low

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor
address _recipient

Check notice

Code scanning / Olympix Integrated Security

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor Low

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor
) MailboxClient(_mailbox) RateLimited(_maxCapacity) {
recipient = _recipient;
}

/// @inheritdoc IInterchainSecurityModule
function moduleType() external pure returns (uint8) {
return uint8(IInterchainSecurityModule.Types.UNUSED);
return uint8(IInterchainSecurityModule.Types.NULL);

Check warning on line 45 in solidity/contracts/isms/warp-route/RateLimitedIsm.sol

View check run for this annotation

Codecov / codecov/patch

solidity/contracts/isms/warp-route/RateLimitedIsm.sol#L45

Added line #L45 was not covered by tests
}

/**
Expand All @@ -42,7 +52,12 @@
function verify(
bytes calldata,
bytes calldata _message
) external validateMessageOnce(_message) returns (bool) {
)
external
yorhodes marked this conversation as resolved.
Show resolved Hide resolved
onlyRecipient(_message)
validateMessageOnce(_message)
returns (bool)
{
require(_isDelivered(_message.id()), "InvalidDeliveredMessage");

uint256 newAmount = _message.body().amount();
Expand Down
23 changes: 20 additions & 3 deletions solidity/test/isms/RateLimitedIsm.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ contract RateLimitedIsmTest is Test {
function setUp() external {
localMailbox = new TestMailbox(ORIGIN);

testRecipient = new TestRecipient();
rateLimitedIsm = new RateLimitedIsm(
address(localMailbox),
MAX_CAPACITY
MAX_CAPACITY,
address(testRecipient)
);
testRecipient = new TestRecipient();

testRecipient.setInterchainSecurityModule(address(rateLimitedIsm));
}

function testRateLimitedIsm_revertsIDeliveredFalse(
bytes calldata _message
uint256 _amount
) external {
bytes memory _message = _encodeTestMessage(_amount);
vm.prank(address(localMailbox));
vm.expectRevert("InvalidDeliveredMessage");
rateLimitedIsm.verify(bytes(""), _message);
Expand All @@ -62,6 +64,21 @@ contract RateLimitedIsmTest is Test {
rateLimitedIsm.verify(bytes(""), encodedMessage);
}

function test_verifyOnlyRecipient(uint128 _amount) external {
bytes memory _message = MessageUtils.formatMessage(
uint8(3),
uint32(1),
ORIGIN,
WARP_ROUTE_ADDR.addressToBytes32(),
ORIGIN,
~address(testRecipient).addressToBytes32(), // bad recipient
TokenMessage.format(bytes32(""), _amount, bytes(""))
);

vm.expectRevert("InvalidRecipient");
rateLimitedIsm.verify(bytes(""), _message);
}

function _encodeTestMessage(
uint256 _amount
) internal view returns (bytes memory) {
Expand Down
Loading