Skip to content

Commit

Permalink
fix: check msg.value is zero when payByApp is true
Browse files Browse the repository at this point in the history
  • Loading branch information
adu-web3 committed Aug 28, 2024
1 parent d2bbefb commit 14ecf30
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/lzApp/OAppSenderUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract contract OAppSenderUpgradeable is OAppCoreUpgradeable {
using SafeERC20 for IERC20;

// Custom error messages
error NotExactNativeFee(uint256 msgValue);
error IncorrectNativeFee(uint256 msgValue);
error LzTokenUnavailable();

// @dev The version of the OAppSender implementation.
Expand Down Expand Up @@ -70,7 +70,7 @@ abstract contract OAppSenderUpgradeable is OAppCoreUpgradeable {
* - nativeFee: The native fee.
* - lzTokenFee: The lzToken fee.
* @param _refundAddress The address to receive any excess fee values sent to the endpoint.
* @param byApp Whether the native fee is paid by the app itself or by the app caller,
* @param payByApp Whether the native fee is paid by the app itself or by the app caller,
* if byApp is true, app caller does not need to specify msg.value to pay for the native fee.
* @return receipt The receipt for the sent message.
* - guid: The unique identifier for the sent message.
Expand All @@ -83,11 +83,11 @@ abstract contract OAppSenderUpgradeable is OAppCoreUpgradeable {
bytes memory _options,
MessagingFee memory _fee,
address _refundAddress,
bool byApp
bool payByApp
) internal virtual returns (MessagingReceipt memory receipt) {
// @dev Push corresponding fees to the endpoint, any excess is sent back to the _refundAddress from the
// endpoint.
uint256 messageValue = _payNative(_fee.nativeFee, byApp);
uint256 messageValue = _payNative(_fee.nativeFee, payByApp);
if (_fee.lzTokenFee > 0) {
_payLzToken(_fee.lzTokenFee);
}
Expand All @@ -102,7 +102,7 @@ abstract contract OAppSenderUpgradeable is OAppCoreUpgradeable {
/**
* @dev Internal function to pay the native fee associated with the message.
* @param _nativeFee The native fee to be paid.
* @param byApp Whether the native fee is paid by the app itself or by the app caller,
* @param payByApp Whether the native fee is paid by the app itself or by the app caller,
* if byApp is true, do not check that the msg.value is equal to nativeFee.
* @return nativeFee The amount of native currency paid.
*
Expand All @@ -112,9 +112,9 @@ abstract contract OAppSenderUpgradeable is OAppCoreUpgradeable {
* @dev Some EVMs use an ERC20 as a method for paying transactions/gasFees.
* @dev The endpoint is EITHER/OR, ie. it will NOT support both types of native payment at a time.
*/
function _payNative(uint256 _nativeFee, bool byApp) internal virtual returns (uint256 nativeFee) {
if (!byApp && msg.value != _nativeFee) {
revert NotExactNativeFee(msg.value);
function _payNative(uint256 _nativeFee, bool payByApp) internal virtual returns (uint256 nativeFee) {
if ((!payByApp && msg.value != _nativeFee) || (payByApp && msg.value != 0)) {
revert IncorrectNativeFee(msg.value);
}
return _nativeFee;
}
Expand Down

0 comments on commit 14ecf30

Please sign in to comment.