From a6139bd90794bfb44914a8d8e8246f846a744a73 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Tue, 2 Apr 2024 20:16:34 +0800 Subject: [PATCH 1/6] Update Bridge.sol --- packages/protocol/contracts/bridge/Bridge.sol | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/packages/protocol/contracts/bridge/Bridge.sol b/packages/protocol/contracts/bridge/Bridge.sol index 98f133d857..7fec4a6b07 100644 --- a/packages/protocol/contracts/bridge/Bridge.sol +++ b/packages/protocol/contracts/bridge/Bridge.sol @@ -407,6 +407,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. @@ -598,4 +640,31 @@ contract Bridge is EssentialContract, IBridge { return false; } } + + /// @notice Checks if the signal was received. + + /// @param _signalService The signal service address. + /// This is the 'readonly' version of _proveSignalReceived. + /// @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).isSignalReceived( + _chainId, resolve(_chainId, "bridge", false), _signal, _proof + ) { + return true; + } catch { + return false; + } + } } From 4ccb31fe80006f3188083e4392f92ab023f8340d Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Tue, 2 Apr 2024 20:26:14 +0800 Subject: [PATCH 2/6] Update Bridge.sol --- packages/protocol/contracts/bridge/Bridge.sol | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/protocol/contracts/bridge/Bridge.sol b/packages/protocol/contracts/bridge/Bridge.sol index 7fec4a6b07..8d43728406 100644 --- a/packages/protocol/contracts/bridge/Bridge.sol +++ b/packages/protocol/contracts/bridge/Bridge.sol @@ -642,9 +642,8 @@ contract Bridge is EssentialContract, IBridge { } /// @notice Checks if the signal was received. - - /// @param _signalService The signal service address. /// 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. From 5e648bcd0329ac144f09a3a26d37281b05dedd75 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Tue, 2 Apr 2024 20:27:29 +0800 Subject: [PATCH 3/6] Update Bridge.sol --- packages/protocol/contracts/bridge/Bridge.sol | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/protocol/contracts/bridge/Bridge.sol b/packages/protocol/contracts/bridge/Bridge.sol index 8d43728406..9c7616b0f8 100644 --- a/packages/protocol/contracts/bridge/Bridge.sol +++ b/packages/protocol/contracts/bridge/Bridge.sol @@ -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. @@ -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. @@ -617,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. From fba8f1989ac9f9e1a561be286429b0bbfed45e1f Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Tue, 2 Apr 2024 20:29:57 +0800 Subject: [PATCH 4/6] rename --- packages/protocol/contracts/bridge/Bridge.sol | 2 +- packages/protocol/contracts/signal/ISignalService.sol | 2 +- packages/protocol/contracts/signal/SignalService.sol | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/protocol/contracts/bridge/Bridge.sol b/packages/protocol/contracts/bridge/Bridge.sol index 9c7616b0f8..cd20c9f7af 100644 --- a/packages/protocol/contracts/bridge/Bridge.sol +++ b/packages/protocol/contracts/bridge/Bridge.sol @@ -660,7 +660,7 @@ contract Bridge is EssentialContract, IBridge { view returns (bool) { - try ISignalService(_signalService).isSignalReceived( + try ISignalService(_signalService).verifySignalReceived( _chainId, resolve(_chainId, "bridge", false), _signal, _proof ) { return true; diff --git a/packages/protocol/contracts/signal/ISignalService.sol b/packages/protocol/contracts/signal/ISignalService.sol index 2677fb468c..b9d94b7e64 100644 --- a/packages/protocol/contracts/signal/ISignalService.sol +++ b/packages/protocol/contracts/signal/ISignalService.sol @@ -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, diff --git a/packages/protocol/contracts/signal/SignalService.sol b/packages/protocol/contracts/signal/SignalService.sol index cc7980a9f0..5ea53860d0 100644 --- a/packages/protocol/contracts/signal/SignalService.sol +++ b/packages/protocol/contracts/signal/SignalService.sol @@ -134,7 +134,7 @@ contract SignalService is EssentialContract, ISignalService { /// @inheritdoc ISignalService /// @dev This function may revert. - function isSignalReceived( + function verifySignalReceived( uint64 _chainId, address _app, bytes32 _signal, From 728b4f0d6a365abaf0d867b0580f69f8f72ed659 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Tue, 2 Apr 2024 20:31:11 +0800 Subject: [PATCH 5/6] Update SignalService.sol --- packages/protocol/contracts/signal/SignalService.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/contracts/signal/SignalService.sol b/packages/protocol/contracts/signal/SignalService.sol index 5ea53860d0..eb7415f3e6 100644 --- a/packages/protocol/contracts/signal/SignalService.sol +++ b/packages/protocol/contracts/signal/SignalService.sol @@ -140,7 +140,7 @@ contract SignalService is EssentialContract, ISignalService { bytes32 _signal, bytes calldata _proof ) - public + external view validSender(_app) nonZeroValue(_signal) From 02ef4a8679f3fecda931cb10fc872fcb26c0e392 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Tue, 2 Apr 2024 22:19:24 +0800 Subject: [PATCH 6/6] Update IBridge.sol --- packages/protocol/contracts/bridge/IBridge.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/contracts/bridge/IBridge.sol b/packages/protocol/contracts/bridge/IBridge.sol index dd2c22ce92..1ff74a032d 100644 --- a/packages/protocol/contracts/bridge/IBridge.sol +++ b/packages/protocol/contracts/bridge/IBridge.sol @@ -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.