Skip to content

Commit 027226b

Browse files
authored
fix: Rewards v2 audit fixes (#346)
* fix: using SafeERC20 * docs: comment
1 parent 91400d9 commit 027226b

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

src/ServiceManagerBase.sol

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
pragma solidity ^0.8.12;
33

44
import {Initializable} from "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
5+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6+
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
57
import {ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/ISignatureUtils.sol";
68
import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
79
import {IRewardsCoordinator} from "eigenlayer-contracts/src/contracts/interfaces/IRewardsCoordinator.sol";
@@ -18,6 +20,7 @@ import {BitmapUtils} from "./libraries/BitmapUtils.sol";
1820
* @author Layr Labs, Inc.
1921
*/
2022
abstract contract ServiceManagerBase is ServiceManagerBaseStorage {
23+
using SafeERC20 for IERC20;
2124
using BitmapUtils for *;
2225

2326
/// @notice when applied to a function, only allows the RegistryCoordinator to call it
@@ -97,18 +100,14 @@ abstract contract ServiceManagerBase is ServiceManagerBaseStorage {
97100
for (uint256 i = 0; i < rewardsSubmissions.length; ++i) {
98101
// transfer token to ServiceManager and approve RewardsCoordinator to transfer again
99102
// in createAVSRewardsSubmission() call
100-
rewardsSubmissions[i].token.transferFrom(
103+
rewardsSubmissions[i].token.safeTransferFrom(
101104
msg.sender,
102105
address(this),
103106
rewardsSubmissions[i].amount
104107
);
105-
uint256 allowance = rewardsSubmissions[i].token.allowance(
106-
address(this),
107-
address(_rewardsCoordinator)
108-
);
109-
rewardsSubmissions[i].token.approve(
108+
rewardsSubmissions[i].token.safeIncreaseAllowance(
110109
address(_rewardsCoordinator),
111-
rewardsSubmissions[i].amount + allowance
110+
rewardsSubmissions[i].amount
112111
);
113112
}
114113

@@ -152,18 +151,15 @@ abstract contract ServiceManagerBase is ServiceManagerBaseStorage {
152151
}
153152

154153
// Transfer token to ServiceManager and approve RewardsCoordinator to transfer again
155-
// in createAVSPerformanceRewardsSubmission() call
156-
operatorDirectedRewardsSubmissions[i].token.transferFrom(
154+
// in createOperatorDirectedAVSRewardsSubmission() call
155+
operatorDirectedRewardsSubmissions[i].token.safeTransferFrom(
157156
msg.sender,
158157
address(this),
159158
totalAmount
160159
);
161-
uint256 allowance = operatorDirectedRewardsSubmissions[i]
162-
.token
163-
.allowance(address(this), address(_rewardsCoordinator));
164-
operatorDirectedRewardsSubmissions[i].token.approve(
160+
operatorDirectedRewardsSubmissions[i].token.safeIncreaseAllowance(
165161
address(_rewardsCoordinator),
166-
totalAmount + allowance
162+
totalAmount
167163
);
168164
}
169165

src/unaudited/ECDSAServiceManagerBase.sol

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
pragma solidity ^0.8.12;
33

44
import {OwnableUpgradeable} from "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
5+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6+
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
57
import {ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/ISignatureUtils.sol";
68
import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
79
import {IServiceManager} from "../interfaces/IServiceManager.sol";
@@ -17,6 +19,8 @@ abstract contract ECDSAServiceManagerBase is
1719
IServiceManager,
1820
OwnableUpgradeable
1921
{
22+
using SafeERC20 for IERC20;
23+
2024
/// @notice Address of the stake registry contract, which manages registration and stake recording.
2125
address public immutable stakeRegistry;
2226

@@ -198,18 +202,14 @@ abstract contract ECDSAServiceManagerBase is
198202
IRewardsCoordinator.RewardsSubmission[] calldata rewardsSubmissions
199203
) internal virtual {
200204
for (uint256 i = 0; i < rewardsSubmissions.length; ++i) {
201-
rewardsSubmissions[i].token.transferFrom(
205+
rewardsSubmissions[i].token.safeTransferFrom(
202206
msg.sender,
203207
address(this),
204208
rewardsSubmissions[i].amount
205209
);
206-
uint256 allowance = rewardsSubmissions[i].token.allowance(
207-
address(this),
208-
rewardsCoordinator
209-
);
210-
rewardsSubmissions[i].token.approve(
210+
rewardsSubmissions[i].token.safeIncreaseAllowance(
211211
rewardsCoordinator,
212-
rewardsSubmissions[i].amount + allowance
212+
rewardsSubmissions[i].amount
213213
);
214214
}
215215

@@ -247,17 +247,14 @@ abstract contract ECDSAServiceManagerBase is
247247

248248
// Transfer token to ServiceManager and approve RewardsCoordinator to transfer again
249249
// in createOperatorDirectedAVSRewardsSubmission() call
250-
operatorDirectedRewardsSubmissions[i].token.transferFrom(
250+
operatorDirectedRewardsSubmissions[i].token.safeTransferFrom(
251251
msg.sender,
252252
address(this),
253253
totalAmount
254254
);
255-
uint256 allowance = operatorDirectedRewardsSubmissions[i]
256-
.token
257-
.allowance(address(this), rewardsCoordinator);
258-
operatorDirectedRewardsSubmissions[i].token.approve(
255+
operatorDirectedRewardsSubmissions[i].token.safeIncreaseAllowance(
259256
rewardsCoordinator,
260-
totalAmount + allowance
257+
totalAmount
261258
);
262259
}
263260

0 commit comments

Comments
 (0)