Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: re-entrancy audit fixes #42

Open
wants to merge 1 commit into
base: kk/sc-15129/sc-operation-executor-gas-optimizations
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"workspaces": {
"packages": [
"packages/**"
]
],
"nohoist": ["**/@openzeppelin/contracts"]
},
"scripts": {
"dev": "lerna run --scope @oasisdex/dma-contracts dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { BALANCER_VAULT } from "../../core/constants/Balancer.sol";
import { ProxyPermission } from "../../libs/DS/ProxyPermission.sol";
import { IERC20 } from "../../libs/SafeERC20.sol";

import "../../libs/FixedPoint.sol";
import { UseStorageSlot, StorageSlot, StorageSlot } from "../../libs/UseStorageSlot.sol";
import { UseRegistry } from "../../libs/UseRegistry.sol";

Expand Down
11 changes: 6 additions & 5 deletions packages/dma-contracts/contracts/core/OperationExecutor.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.24;

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import { OperationsRegistry } from "./OperationsRegistry.sol";
import { ServiceRegistry } from "../core/ServiceRegistry.sol";
import { ChainLogView } from "../core/views/ChainLogView.sol";
Expand Down Expand Up @@ -31,7 +32,7 @@ interface IProxy {
* Also it acts as a flashloan recipient
*/

contract OperationExecutor is IERC3156FlashBorrower, IFlashLoanRecipient, UseStorageSlot {
contract OperationExecutor is IERC3156FlashBorrower, IFlashLoanRecipient, UseStorageSlot, ReentrancyGuard {
using ActionAddress for address;
using SafeERC20 for IERC20;
using StorageSlot for bytes32;
Expand Down Expand Up @@ -83,7 +84,7 @@ contract OperationExecutor is IERC3156FlashBorrower, IFlashLoanRecipient, UseSto
*
* @param calls List of action calls to be executed.
*/
function executeOp(Call[] memory calls) external payable returns (bytes32) {
function executeOp(Call[] memory calls) external nonReentrant payable returns (bytes32) {
aggregate(calls);

bytes32[] memory actions = getActionsStorageSlot().returnStoredArray();
Expand Down Expand Up @@ -145,7 +146,7 @@ contract OperationExecutor is IERC3156FlashBorrower, IFlashLoanRecipient, UseSto
FlashloanData memory flData = abi.decode(data, (FlashloanData));

address mcdFlash = CHAINLOG_VIEWER.getServiceAddress(MCD_FLASH);
checkIfLenderIsTrusted(mcdFlash);
checkIfSenderIsTrusted(mcdFlash);
checkIfFlashloanedAssetIsTheRequiredOne(asset, flData.asset);
checkIfFlashloanedAmountIsTheRequiredOne(asset, flData.amount);
processFlashloan(flData, initiator);
Expand Down Expand Up @@ -180,7 +181,7 @@ contract OperationExecutor is IERC3156FlashBorrower, IFlashLoanRecipient, UseSto
address asset = address(tokens[0]);
(FlashloanData memory flData, address initiator) = abi.decode(data, (FlashloanData, address));

checkIfLenderIsTrusted(BALANCER_VAULT);
checkIfSenderIsTrusted(BALANCER_VAULT);
checkIfFlashloanedAssetIsTheRequiredOne(asset, flData.asset);
checkIfFlashloanedAmountIsTheRequiredOne(asset, flData.amount);

Expand All @@ -196,7 +197,7 @@ contract OperationExecutor is IERC3156FlashBorrower, IFlashLoanRecipient, UseSto
IERC20(asset).safeTransfer(BALANCER_VAULT, paybackAmount);
}

function checkIfLenderIsTrusted(address lender) public view {
function checkIfSenderIsTrusted(address lender) public view {
if (msg.sender != lender) revert UntrustedLender(msg.sender);
}

Expand Down
1 change: 0 additions & 1 deletion packages/dma-contracts/hardhat.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ const config = {
},
hardfork: 'cancun',
gas: 'auto',
initialBaseFeePerGas: 1000000000,
allowUnlimitedContractSize: true,
},
...(includeGoerli
Expand Down
Loading