Skip to content

Commit 5ef660d

Browse files
committed
fix: incorrect verifications
1 parent a57b6bf commit 5ef660d

File tree

4 files changed

+28
-34
lines changed

4 files changed

+28
-34
lines changed

contracts/src/bridge/FastBridgeReceiverOnEthereum.sol

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,10 @@ contract FastBridgeReceiverOnEthereum is SafeBridgeReceiverOnEthereum, IFastBrid
106106
emit ClaimChallenged(_ticketID, ticket.claim.messageHash, block.timestamp);
107107
}
108108

109-
function verifyAndRelay(
110-
uint256 _ticketID,
111-
bytes32 _messageHash,
112-
bytes memory _messageData
113-
) external override {
114-
require(_verify(_messageHash, _ticketID, _messageData), "Invalid hash");
115-
109+
function verifyAndRelay(uint256 _ticketID, bytes memory _messageData) external override {
116110
Ticket storage ticket = tickets[_ticketID];
117111
require(ticket.claim.bridger != address(0), "Claim does not exist");
112+
require(ticket.claim.messageHash == keccak256(abi.encode(_ticketID, _messageData)), "Invalid hash");
118113
require(ticket.claim.claimedAt + challengeDuration < block.timestamp, "Challenge period not over");
119114
require(ticket.challenge.challenger == address(0), "Claim is challenged");
120115
require(ticket.relayed == false, "Message already relayed");
@@ -124,19 +119,15 @@ contract FastBridgeReceiverOnEthereum is SafeBridgeReceiverOnEthereum, IFastBrid
124119
require(_relay(_messageData), "Failed to call contract"); // Checks-Effects-Interaction
125120
}
126121

127-
function verifyAndRelaySafe(
128-
uint256 _ticketID,
129-
bytes32 _messageHash,
130-
bytes memory _messageData
131-
) external override {
122+
function verifyAndRelaySafe(uint256 _ticketID, bytes memory _messageData) external override {
132123
require(isSentBySafeBridge(), "Access not allowed: SafeBridgeSender only.");
133-
require(_verify(_messageHash, _ticketID, _messageData), "Invalid hash");
134124

135125
Ticket storage ticket = tickets[_ticketID];
136126
require(ticket.relayed == false, "Message already relayed");
137127

138128
// Claim assessment if any
139-
if (ticket.claim.bridger != address(0) && ticket.claim.messageHash == _messageHash) {
129+
bytes32 messageHash = keccak256(abi.encode(_ticketID, _messageData));
130+
if (ticket.claim.bridger != address(0) && ticket.claim.messageHash == messageHash) {
140131
ticket.claim.verified = true;
141132
}
142133

@@ -203,14 +194,6 @@ contract FastBridgeReceiverOnEthereum is SafeBridgeReceiverOnEthereum, IFastBrid
203194
// * Internal * //
204195
// ************************ //
205196

206-
function _verify(
207-
bytes32 _expectedHash,
208-
uint256 _ticketID,
209-
bytes memory _messageData
210-
) internal pure returns (bool) {
211-
return _expectedHash == keccak256(abi.encode(_ticketID, _messageData));
212-
}
213-
214197
function _relay(bytes memory _messageData) internal returns (bool success) {
215198
// Decode the receiver address from the data encoded by the IFastBridgeSender
216199
(address receiver, bytes memory data) = abi.decode(_messageData, (address, bytes));

contracts/src/bridge/FastBridgeSenderToEthereum.sol

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ import "./interfaces/IFastBridgeReceiver.sol";
1919
* Counterpart of `FastBridgeReceiverOnEthereum`
2020
*/
2121
contract FastBridgeSenderToEthereum is SafeBridgeSenderToEthereum, IFastBridgeSender {
22+
// ************************************* //
23+
// * Enums / Structs * //
24+
// ************************************* //
25+
26+
struct Ticket {
27+
bytes32 messageHash;
28+
bool sentSafe;
29+
}
30+
2231
// ************************************* //
2332
// * Storage * //
2433
// ************************************* //
@@ -27,6 +36,7 @@ contract FastBridgeSenderToEthereum is SafeBridgeSenderToEthereum, IFastBridgeSe
2736
IFastBridgeReceiver public fastBridgeReceiver;
2837
address public fastSender;
2938
uint256 public currentTicketID = 1; // Zero means not set, start at 1.
39+
mapping(uint256 => Ticket) public tickets; // The tickets by ticketID.
3040

3141
// ************************************* //
3242
// * Events * //
@@ -68,8 +78,11 @@ contract FastBridgeSenderToEthereum is SafeBridgeSenderToEthereum, IFastBridgeSe
6878
require(msg.sender == fastSender, "Access not allowed: Fast Sender only.");
6979

7080
ticketID = currentTicketID++;
81+
7182
(bytes32 messageHash, bytes memory messageData) = _encode(ticketID, _receiver, _calldata);
7283
emit OutgoingMessage(ticketID, _receiver, messageHash, messageData);
84+
85+
tickets[ticketID] = Ticket({messageHash: messageHash, sentSafe: false});
7386
}
7487

7588
/**
@@ -90,11 +103,16 @@ contract FastBridgeSenderToEthereum is SafeBridgeSenderToEthereum, IFastBridgeSe
90103
address _receiver,
91104
bytes memory _calldata
92105
) external payable override {
106+
Ticket storage ticket = tickets[_ticketID];
107+
require(ticket.messageHash != 0, "Ticket does not exist.");
108+
require(ticket.sentSafe == false, "Ticket already sent safely.");
109+
93110
(bytes32 messageHash, bytes memory messageData) = _encode(_ticketID, _receiver, _calldata);
111+
require(ticket.messageHash == messageHash, "Invalid message for ticketID.");
94112

95113
// Safe Bridge message envelope
96114
bytes4 methodSelector = IFastBridgeReceiver.verifyAndRelaySafe.selector;
97-
bytes memory safeMessageData = abi.encodeWithSelector(methodSelector, _ticketID, messageHash, messageData);
115+
bytes memory safeMessageData = abi.encodeWithSelector(methodSelector, _ticketID, messageData);
98116

99117
// TODO: how much ETH should be provided for bridging? add an ISafeBridgeSender.bridgingCost() if needed
100118
_sendSafe(address(fastBridgeReceiver), safeMessageData);

contracts/src/bridge/interfaces/IFastBridgeReceiver.sol

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@ interface IFastBridgeReceiver {
77

88
function challenge(uint256 _ticketID) external payable;
99

10-
function verifyAndRelay(
11-
uint256 _ticketID,
12-
bytes32 _messageHash,
13-
bytes memory _messageData
14-
) external;
15-
16-
function verifyAndRelaySafe(
17-
uint256 _ticketID,
18-
bytes32 _messageHash,
19-
bytes memory _messageData
20-
) external;
10+
function verifyAndRelay(uint256 _ticketID, bytes memory _messageData) external;
11+
12+
function verifyAndRelaySafe(uint256 _ticketID, bytes memory _messageData) external;
2113

2214
function withdrawClaimDeposit(uint256 _ticketID) external;
2315

contracts/src/bridge/interfaces/IFastBridgeSender.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface IFastBridgeSender {
1616
* Sends an arbitrary message from one domain to another
1717
* via the fast bridge mechanism
1818
*
19+
* @param _ticketID The identifier to provide to sendSafeFallback()
1920
* @param _receiver The L1 contract address who will receive the calldata
2021
* @param _calldata The receiving domain encoded message data.
2122
*/

0 commit comments

Comments
 (0)