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

feat(protocol): add readonly functions isMessageFailed & isMessageReceived to Bridge #16608

Merged
merged 7 commits into from
Apr 2, 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
76 changes: 73 additions & 3 deletions packages/protocol/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ contract Bridge is EssentialContract, IBridge {
});
}

/// @notice Checks if a msgHash has failed on its destination chain.
/// @notice Checks if a msgHash has failed on its destination chain and caches cross-chain data
/// if requested.
/// @param _message The message.
/// @param _proof The merkle inclusion proof.
/// @return true if the message has failed, false otherwise.
Expand All @@ -390,7 +391,8 @@ contract Bridge is EssentialContract, IBridge {
);
}

/// @notice Checks if a msgHash has failed on its destination chain.
/// @notice Checks if a msgHash has failed on its destination chain and caches cross-chain data
/// if requested.
/// @param _message The message.
/// @param _proof The merkle inclusion proof.
/// @return true if the message has failed, false otherwise.
Expand All @@ -407,6 +409,48 @@ contract Bridge is EssentialContract, IBridge {
);
}

/// @notice Checks if a msgHash has failed on its destination chain.
/// This is the 'readonly' version of proveMessageFailed.
/// @param _message The message.
/// @param _proof The merkle inclusion proof.
/// @return true if the message has failed, false otherwise.
function isMessageFailed(
Message calldata _message,
bytes calldata _proof
)
external
view
returns (bool)
{
if (_message.srcChainId != block.chainid) return false;

return _isSignalReceived(
resolve("signal_service", false),
signalForFailedMessage(hashMessage(_message)),
_message.destChainId,
_proof
);
}

/// @notice Checks if a msgHash has failed on its destination chain.
/// This is the 'readonly' version of proveMessageReceived.
/// @param _message The message.
/// @param _proof The merkle inclusion proof.
/// @return true if the message has failed, false otherwise.
function isMessageReceived(
Message calldata _message,
bytes calldata _proof
)
external
view
returns (bool)
{
if (_message.destChainId != block.chainid) return false;
return _isSignalReceived(
resolve("signal_service", false), hashMessage(_message), _message.srcChainId, _proof
);
}

/// @notice Checks if the destination chain is enabled.
/// @param _chainId The destination chain ID.
/// @return enabled_ True if the destination chain is enabled.
Expand Down Expand Up @@ -575,7 +619,7 @@ contract Bridge is EssentialContract, IBridge {
}
}

/// @notice Checks if the signal was received.
/// @notice Checks if the signal was received and caches cross-chain data if requested.
/// @param _signalService The signal service address.
/// @param _signal The signal.
/// @param _chainId The ID of the chain the signal is stored on.
Expand All @@ -598,4 +642,30 @@ contract Bridge is EssentialContract, IBridge {
return false;
}
}

/// @notice Checks if the signal was received.
/// This is the 'readonly' version of _proveSignalReceived.
/// @param _signalService The signal service address.
/// @param _signal The signal.
/// @param _chainId The ID of the chain the signal is stored on.
/// @param _proof The merkle inclusion proof.
/// @return true if the message was received.
function _isSignalReceived(
address _signalService,
bytes32 _signal,
uint64 _chainId,
bytes calldata _proof
)
private
view
returns (bool)
{
try ISignalService(_signalService).verifySignalReceived(
_chainId, resolve(_chainId, "bridge", false), _signal, _proof
) {
return true;
} catch {
return false;
}
}
}
2 changes: 1 addition & 1 deletion packages/protocol/contracts/bridge/IBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ interface IBridge {
event AddressBanned(address indexed addr, bool banned);

/// @notice Sends a message to the destination chain and takes custody
/// of Ether required in this contract. All extra Ether will be refunded.
/// of Ether required in this contract.
/// @param _message The message to be sent.
/// @return msgHash_ The hash of the sent message.
/// @return message_ The updated message sent.
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/signal/ISignalService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ interface ISignalService {
/// @param _signal The signal (message) to send.
/// @param _proof Merkle proof that the signal was persisted on the
/// source chain.
function isSignalReceived(
function verifySignalReceived(
uint64 _chainId,
address _app,
bytes32 _signal,
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/contracts/signal/SignalService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ contract SignalService is EssentialContract, ISignalService {

/// @inheritdoc ISignalService
/// @dev This function may revert.
function isSignalReceived(
function verifySignalReceived(
uint64 _chainId,
address _app,
bytes32 _signal,
bytes calldata _proof
)
public
external
view
validSender(_app)
nonZeroValue(_signal)
Expand Down
Loading