Skip to content

Commit 8751ec2

Browse files
committed
Ovault - audit paladin (#1652)
Signed-off-by: shankar <shankar@layerzerolabs.org>
1 parent 634b4ba commit 8751ec2

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

packages/ovault-evm/contracts/VaultComposerSync.sol

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.22;
33

44
import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
5-
import { IERC4626 } from "@openzeppelin/contracts/interfaces/IERC4626.sol";
5+
import { ERC4626, IERC4626 } from "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";
66

77
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
88

@@ -273,22 +273,34 @@ contract VaultComposerSync is IVaultComposerSync, ReentrancyGuard {
273273
/**
274274
* @notice Quotes the send operation for the given OFT and SendParam
275275
* @dev Revert on slippage will be thrown by the OFT and not _assertSlippage
276+
* @param _from The "sender address" used for the quote
276277
* @param _targetOFT The OFT contract address to quote
277278
* @param _vaultInAmount The amount of tokens to send to the vault
278279
* @param _sendParam The parameters for the send operation
279280
* @return MessagingFee The estimated fee for the send operation
280281
* @dev This function can be overridden to implement custom quoting logic
281282
*/
282283
function quoteSend(
284+
address _from,
283285
address _targetOFT,
284286
uint256 _vaultInAmount,
285287
SendParam memory _sendParam
286288
) external view virtual returns (MessagingFee memory) {
287289
/// @dev When quoting the asset OFT, the function input is shares and the SendParam.amountLD into quoteSend() should be assets (and vice versa)
288290

289291
if (_targetOFT == ASSET_OFT) {
292+
uint256 maxRedeem = VAULT.maxRedeem(_from);
293+
if (_vaultInAmount > maxRedeem) {
294+
revert ERC4626.ERC4626ExceededMaxRedeem(_from, _vaultInAmount, maxRedeem);
295+
}
296+
290297
_sendParam.amountLD = VAULT.previewRedeem(_vaultInAmount);
291298
} else {
299+
uint256 maxDeposit = VAULT.maxDeposit(_from);
300+
if (_vaultInAmount > maxDeposit) {
301+
revert ERC4626.ERC4626ExceededMaxDeposit(_from, _vaultInAmount, maxDeposit);
302+
}
303+
292304
_sendParam.amountLD = VAULT.previewDeposit(_vaultInAmount);
293305
}
294306
return IOFT(_targetOFT).quoteSend(_sendParam, false);

packages/ovault-evm/contracts/interfaces/IVaultComposerSync.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ interface IVaultComposerSync is IOAppComposer {
5656

5757
/**
5858
* @notice Quotes the send operation for the given OFT and SendParam
59+
* @param from The "sender address" used for the quote
5960
* @param targetOft The OFT contract address to quote
6061
* @param vaultInAmount The amount of tokens to send to the vault
6162
* @param sendParam The parameters for the send operation
6263
* @return MessagingFee The estimated fee for the send operation
6364
* @dev This function can be overridden to implement custom quoting logic
6465
*/
6566
function quoteSend(
67+
address from,
6668
address targetOft,
6769
uint256 vaultInAmount,
6870
SendParam memory sendParam

packages/ovault-evm/test/vault-sync/VaultComposerSync_ProxySend.t.sol

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ contract VaultComposerSyncProxySendTest is VaultComposerSyncBaseTest {
102102
SendParam memory sendParam = SendParam(POL_EID, addressToBytes32(userA), TOKENS_TO_SEND, 0, "", "", "");
103103
assetOFT_arb.mint(address(userA), TOKENS_TO_SEND);
104104

105-
MessagingFee memory fee = VaultComposerSyncArb.quoteSend(address(assetOFT_arb), TOKENS_TO_SEND, sendParam);
105+
MessagingFee memory fee = VaultComposerSyncArb.quoteSend(
106+
userA,
107+
address(shareOFT_arb),
108+
TOKENS_TO_SEND,
109+
sendParam
110+
);
106111

107112
vm.startPrank(userA);
108113
assetOFT_arb.approve(address(VaultComposerSyncArb), TOKENS_TO_SEND);
@@ -123,7 +128,12 @@ contract VaultComposerSyncProxySendTest is VaultComposerSyncBaseTest {
123128
assetOFT_arb.mint(address(vault_arb), TOKENS_TO_SEND);
124129
vault_arb.mint(address(userA), TOKENS_TO_SEND);
125130

126-
MessagingFee memory fee = VaultComposerSyncArb.quoteSend(address(shareOFT_arb), TOKENS_TO_SEND, sendParam);
131+
MessagingFee memory fee = VaultComposerSyncArb.quoteSend(
132+
userA,
133+
address(assetOFT_arb),
134+
TOKENS_TO_SEND,
135+
sendParam
136+
);
127137

128138
vm.startPrank(userA);
129139
vault_arb.approve(address(VaultComposerSyncArb), TOKENS_TO_SEND);

0 commit comments

Comments
 (0)