@@ -247,17 +247,7 @@ contract TokenMessengerV2 is IMessageHandlerV2, BaseTokenMessenger {
247
247
onlyRemoteTokenMessenger (remoteDomain, sender)
248
248
returns (bool )
249
249
{
250
- // Validate finalized message
251
- bytes29 _msg = messageBody.ref (0 );
252
- (
253
- address _mintRecipient ,
254
- bytes32 _burnToken ,
255
- uint256 _amount
256
- ) = _validateFinalizedMessage (_msg);
257
-
258
- _mintAndWithdraw (remoteDomain, _burnToken, _mintRecipient, _amount, 0 );
259
-
260
- return true ;
250
+ return _handleReceiveMessage (messageBody.ref (0 ), remoteDomain);
261
251
}
262
252
263
253
/**
@@ -291,24 +281,7 @@ contract TokenMessengerV2 is IMessageHandlerV2, BaseTokenMessenger {
291
281
"Unsupported finality threshold "
292
282
);
293
283
294
- // Validate message
295
- bytes29 _msg = messageBody.ref (0 );
296
- (
297
- address _mintRecipient ,
298
- bytes32 _burnToken ,
299
- uint256 _amount ,
300
- uint256 _fee
301
- ) = _validateUnfinalizedMessage (_msg);
302
-
303
- _mintAndWithdraw (
304
- remoteDomain,
305
- _burnToken,
306
- _mintRecipient,
307
- _amount - _fee,
308
- _fee
309
- );
310
-
311
- return true ;
284
+ return _handleReceiveMessage (messageBody.ref (0 ), remoteDomain);
312
285
}
313
286
314
287
// ============ Internal Utils ============
@@ -379,46 +352,51 @@ contract TokenMessengerV2 is IMessageHandlerV2, BaseTokenMessenger {
379
352
}
380
353
381
354
/**
382
- * @notice Validates a finalized BurnMessage and unpacks relevant message fields.
383
- * @dev Reverts if the BurnMessage is malformed
384
- * @dev Reverts if the BurnMessage version isn't supported
385
- * @param _msg Finalized message
386
- * @return _mintRecipient The recipient of the mint, as bytes32
387
- * @return _burnToken The address of the token burned on the source chain
388
- * @return _amount The amount of burnToken burned
355
+ * @notice Validates a received message and mints the token to the mintRecipient, less fees.
356
+ * @dev Reverts if _validatedReceivedMessage fails to validate the message.
357
+ * @dev Reverts if the mint operation fails.
358
+ * @param _msg Received message
359
+ * @param _remoteDomain The domain where the message originated from
360
+ * @return success Bool, true if successful.
389
361
*/
390
- function _validateFinalizedMessage (
391
- bytes29 _msg
392
- )
393
- internal
394
- view
395
- returns (address _mintRecipient , bytes32 _burnToken , uint256 _amount )
396
- {
397
- _msg._validateBurnMessageFormat ();
398
- require (
399
- _msg._getVersion () == messageBodyVersion,
400
- "Invalid message body version "
401
- );
362
+ function _handleReceiveMessage (
363
+ bytes29 _msg ,
364
+ uint32 _remoteDomain
365
+ ) internal returns (bool ) {
366
+ // Validate message and unpack fields
367
+ (
368
+ address _mintRecipient ,
369
+ bytes32 _burnToken ,
370
+ uint256 _amount ,
371
+ uint256 _fee
372
+ ) = _validatedReceivedMessage (_msg);
402
373
403
- return (
404
- _msg._getMintRecipient ().toAddress (),
405
- _msg._getBurnToken (),
406
- _msg._getAmount ()
374
+ // Mint tokens
375
+ _mintAndWithdraw (
376
+ _remoteDomain,
377
+ _burnToken,
378
+ _mintRecipient,
379
+ _amount - _fee,
380
+ _fee
407
381
);
382
+
383
+ return true ;
408
384
}
409
385
410
386
/**
411
- * @notice Validates a finalized BurnMessage and unpacks relevant message fields.
387
+ * @notice Validates a BurnMessage and unpacks relevant fields.
412
388
* @dev Reverts if the BurnMessage is malformed
413
389
* @dev Reverts if the BurnMessage version isn't supported
414
- * @dev Reverts if the message is expired
415
- * @dev Reverts if the fee executed exceeds the amount
390
+ * @dev Reverts if the BurnMessage has expired
391
+ * @dev Reverts if the fee equals or exceeds the amount
392
+ * @dev Reverts if the fee exceeds the max fee specified on the source chain
416
393
* @param _msg Finalized message
417
394
* @return _mintRecipient The recipient of the mint, as bytes32
418
395
* @return _burnToken The address of the token burned on the source chain
419
396
* @return _amount The amount of burnToken burned
397
+ * @return _fee The fee executed
420
398
*/
421
- function _validateUnfinalizedMessage (
399
+ function _validatedReceivedMessage (
422
400
bytes29 _msg
423
401
)
424
402
internal
@@ -430,7 +408,11 @@ contract TokenMessengerV2 is IMessageHandlerV2, BaseTokenMessenger {
430
408
uint256 _fee
431
409
)
432
410
{
433
- (_mintRecipient, _burnToken, _amount) = _validateFinalizedMessage (_msg);
411
+ _msg._validateBurnMessageFormat ();
412
+ require (
413
+ _msg._getVersion () == messageBodyVersion,
414
+ "Invalid message body version "
415
+ );
434
416
435
417
// Enforce message expiration
436
418
uint256 _expirationBlock = _msg._getExpirationBlock ();
@@ -440,8 +422,12 @@ contract TokenMessengerV2 is IMessageHandlerV2, BaseTokenMessenger {
440
422
);
441
423
442
424
// Validate fee
425
+ _amount = _msg._getAmount ();
443
426
_fee = _msg._getFeeExecuted ();
444
427
require (_fee == 0 || _fee < _amount, "Fee equals or exceeds amount " );
445
428
require (_fee <= _msg._getMaxFee (), "Fee exceeds max fee " );
429
+
430
+ _mintRecipient = _msg._getMintRecipient ().toAddress ();
431
+ _burnToken = _msg._getBurnToken ();
446
432
}
447
433
}
0 commit comments