Skip to content

Commit

Permalink
Change flashLoan and receiveFlashLoan to explicitly only allow calls …
Browse files Browse the repository at this point in the history
…from the boring vault and the balancer vault respectively
  • Loading branch information
crispymangoes committed Apr 8, 2024
1 parent 0dec573 commit 2921e0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/base/Roles/ManagerWithMerkleVerification.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ contract ManagerWithMerkleVerification is Auth {
error ManagerWithMerkleVerification__BadFlashLoanIntentHash();
error ManagerWithMerkleVerification__FailedToVerifyManageProof(address target, bytes targetData, uint256 value);
error ManagerWithMerkleVerification__Paused();
error ManagerWithMerkleVerification__OnlyCallableByBoringVault();
error ManagerWithMerkleVerification__OnlyCallableByBalancerVault();

//============================== EVENTS ===============================

Expand Down Expand Up @@ -156,7 +158,9 @@ contract ManagerWithMerkleVerification is Auth {
address[] calldata tokens,
uint256[] calldata amounts,
bytes calldata userData
) external requiresAuth {
) external {
if (msg.sender != address(vault)) revert ManagerWithMerkleVerification__OnlyCallableByBoringVault();

flashLoanIntentHash = keccak256(userData);
performingFlashLoan = true;
balancerVault.flashLoan(recipient, tokens, amounts, userData);
Expand All @@ -175,7 +179,8 @@ contract ManagerWithMerkleVerification is Auth {
uint256[] calldata amounts,
uint256[] calldata feeAmounts,
bytes calldata userData
) external requiresAuth {
) external {
if (msg.sender != address(balancerVault)) revert ManagerWithMerkleVerification__OnlyCallableByBalancerVault();
if (!performingFlashLoan) revert ManagerWithMerkleVerification__FlashLoanNotInProgress();

// Validate userData using intentHash.
Expand Down
17 changes: 15 additions & 2 deletions test/ManagerWithMerkleVerification.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1541,14 +1541,27 @@ contract ManagerWithMerkleVerificationTest is Test, MainnetAddresses {
// Call now works.
manager.manageVaultWithMerkleVerification(manageProofs, decodersAndSanitizers, targets, targetData, values);

// Check `receiveFlashLoan`
// Check `flashLoan`
address[] memory tokens;
uint256[] memory amounts;

vm.expectRevert(
abi.encodeWithSelector(
ManagerWithMerkleVerification.ManagerWithMerkleVerification__OnlyCallableByBoringVault.selector
)
);
manager.flashLoan(address(this), tokens, amounts, abi.encode(0));

// Check `receiveFlashLoan`
uint256[] memory feeAmounts;

address attacker = vm.addr(1);
vm.startPrank(attacker);
vm.expectRevert(bytes("UNAUTHORIZED"));
vm.expectRevert(
abi.encodeWithSelector(
ManagerWithMerkleVerification.ManagerWithMerkleVerification__OnlyCallableByBalancerVault.selector
)
);
manager.receiveFlashLoan(tokens, amounts, feeAmounts, abi.encode(0));
vm.stopPrank();

Expand Down

0 comments on commit 2921e0c

Please sign in to comment.