Skip to content

Commit

Permalink
feat(protocol): check message.to on source chain as well (#13107)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Feb 8, 2023
1 parent 315c5e6 commit b55a646
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 7 additions & 3 deletions packages/protocol/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,13 @@ contract Bridge is EssentialContract, IBridge {
return state.ctx;
}

function isDestChainEnabled(uint256 _chainId) public view returns (bool) {
return
LibBridgeSend.isDestChainEnabled(AddressResolver(this), _chainId);
function isDestChainEnabled(
uint256 _chainId
) public view returns (bool enabled) {
(enabled, ) = LibBridgeSend.isDestChainEnabled(
AddressResolver(this),
_chainId
);
}

function hashMessage(
Expand Down
14 changes: 10 additions & 4 deletions packages/protocol/contracts/bridge/libs/LibBridgeSend.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ library LibBridgeSend {
IBridge.Message memory message
) internal returns (bytes32 msgHash) {
require(message.owner != address(0), "B:owner");

(bool destChainEnabled, address destChain) = isDestChainEnabled(
resolver,
message.destChainId
);
require(
message.destChainId != block.chainid &&
isDestChainEnabled(resolver, message.destChainId),
destChainEnabled && message.destChainId != block.chainid,
"B:destChainId"
);
require(message.to != address(0) && message.to != destChain, "B:to");

uint256 expectedAmount = message.depositValue +
message.callValue +
Expand Down Expand Up @@ -72,8 +77,9 @@ library LibBridgeSend {
function isDestChainEnabled(
AddressResolver resolver,
uint256 chainId
) internal view returns (bool) {
return resolver.resolve(chainId, "bridge", true) != address(0);
) internal view returns (bool enabled, address destBridge) {
destBridge = resolver.resolve(chainId, "bridge", true);
enabled = destBridge != address(0);
}

function isMessageSent(
Expand Down

0 comments on commit b55a646

Please sign in to comment.