fix: only evaluate dynamic revert reasons in reverting branch (#4046)

### Description

Optimize non-reverting branch gas usage caused by building dynamic
revert reason strings

### Testing

Unit Tests
pull/4290/head
Yorke Rhodes 4 months ago committed by GitHub
parent 69fba689b9
commit 2edfa40435
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/real-guests-search.md
  2. 6
      solidity/contracts/client/Router.sol
  3. 16
      solidity/contracts/hooks/igp/InterchainGasPaymaster.sol
  4. 15
      solidity/contracts/hooks/routing/DomainRoutingHook.sol
  5. 6
      solidity/contracts/isms/routing/DomainRoutingIsm.sol

@ -0,0 +1,5 @@
---
"@hyperlane-xyz/core": patch
---
fix: only evaluate dynamic revert reasons in reverting branch

@ -153,8 +153,10 @@ abstract contract Router is MailboxClient, IMessageRecipient {
uint32 _domain
) internal view returns (bytes32) {
(bool contained, bytes32 _router) = _routers.tryGet(_domain);
require(contained, _domainNotFoundError(_domain));
return _router;
if (contained) {
return _router;
}
revert(_domainNotFoundError(_domain));
}
function _domainNotFoundError(

@ -228,14 +228,14 @@ contract InterchainGasPaymaster is
IGasOracle _gasOracle = destinationGasConfigs[_destinationDomain]
.gasOracle;
require(
address(_gasOracle) != address(0),
string.concat(
"Configured IGP doesn't support domain ",
Strings.toString(_destinationDomain)
)
);
if (address(_gasOracle) == address(0)) {
revert(
string.concat(
"Configured IGP doesn't support domain ",
Strings.toString(_destinationDomain)
)
);
}
return _gasOracle.getExchangeRateAndGasPrice(_destinationDomain);
}

@ -90,12 +90,13 @@ contract DomainRoutingHook is AbstractPostDispatchHook, MailboxClient {
bytes calldata message
) internal view virtual returns (IPostDispatchHook hook) {
hook = hooks[message.destination()];
require(
address(hook) != address(0),
string.concat(
"No hook configured for destination: ",
message.destination().toString()
)
);
if (address(hook) == address(0)) {
revert(
string.concat(
"No hook configured for destination: ",
message.destination().toString()
)
);
}
}
}

@ -85,8 +85,10 @@ contract DomainRoutingIsm is AbstractRoutingIsm, OwnableUpgradeable {
uint32 origin
) public view virtual returns (IInterchainSecurityModule) {
(bool contained, bytes32 _module) = _modules.tryGet(origin);
require(contained, _originNotFoundError(origin));
return IInterchainSecurityModule(_module.bytes32ToAddress());
if (contained) {
return IInterchainSecurityModule(_module.bytes32ToAddress());
}
revert(_originNotFoundError(origin));
}
// ============ Public Functions ============

Loading…
Cancel
Save