If the user specifies native tokens as output assets, the protocol will mistakenly try to unwrap wrapped tokens from the msg.sender instead of the receiver address that was specified in the function call.
Proof of Concept
This issue occurs in the following modules:
BVault
CrossLending
IsolateLending
Users are allowed to specify an output asset when borrowing/withdrawing funds from the protocol. If the output asset is a native token, a wrapped version will be sent to the receiver via the erc20TransferOutLiquidity function, and then the receiver of these tokens must send them to the protocol, which will unwrap and send them back:
The problem here is that the wrapped tokens will be sent to the params.receiver address, but the unwrapNativeTokenInWallet function will try to get them from msg.sender, who may not have them in the wallet. As a result withdraw/borrow functionality may fail if msg.sender != receiver:
Lines of code
https://github.com/code-423n4/2024-07-benddao/blob/main/src/modules/BVault.sol#L74 https://github.com/code-423n4/2024-07-benddao/blob/main/src/modules/CrossLending.sol#L50 https://github.com/code-423n4/2024-07-benddao/blob/main/src/modules/IsolateLending.sol#L51
Vulnerability details
Impact
If the user specifies native tokens as output assets, the protocol will mistakenly try to unwrap wrapped tokens from the
msg.sender
instead of thereceiver
address that was specified in the function call.Proof of Concept
This issue occurs in the following modules:
Users are allowed to specify an output asset when borrowing/withdrawing funds from the protocol. If the output asset is a native token, a wrapped version will be sent to the receiver via the
erc20TransferOutLiquidity
function, and then the receiver of these tokens must send them to the protocol, which will unwrap and send them back:The problem here is that the wrapped tokens will be sent to the
params.receiver
address, but theunwrapNativeTokenInWallet
function will try to get them frommsg.sender
, who may not have them in the wallet. As a result withdraw/borrow functionality may fail ifmsg.sender
!=receiver
:Same in
crossBorrowERC20
andisolateBorrow
functions.Tools Used
Manual review
Recommended Mitigation Steps
Assessed type
Token-Transfer