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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(protocol): check message.to on source chain as well #13107

Merged
merged 3 commits into from
Feb 8, 2023
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
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