Skip to content

Commit 0e0d946

Browse files
committed
prevent admin from accidentally being configured as a known subaccount
- Spearbit #9
1 parent cfe1254 commit 0e0d946

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/EulerSwapProtocolFeeConfig.sol

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ contract EulerSwapProtocolFeeConfig is IEulerSwapProtocolFeeConfig, EVCUtil {
2929
mapping(address pool => Override) public overrides;
3030

3131
error Unauthorized();
32+
error InvalidAdminAddress();
3233
error InvalidProtocolFee();
3334
error InvalidProtocolFeeRecipient();
3435

@@ -42,6 +43,8 @@ contract EulerSwapProtocolFeeConfig is IEulerSwapProtocolFeeConfig, EVCUtil {
4243
event OverrideRemoved(address indexed pool);
4344

4445
constructor(address evc, address admin_) EVCUtil(evc) {
46+
_validateAdminAddress(admin_);
47+
4548
emit AdminUpdated(address(0), admin_);
4649

4750
admin = admin_;
@@ -58,6 +61,8 @@ contract EulerSwapProtocolFeeConfig is IEulerSwapProtocolFeeConfig, EVCUtil {
5861

5962
/// @inheritdoc IEulerSwapProtocolFeeConfig
6063
function setAdmin(address newAdmin) external onlyAdmin {
64+
_validateAdminAddress(newAdmin);
65+
6166
emit AdminUpdated(admin, newAdmin);
6267

6368
admin = newAdmin;
@@ -104,4 +109,10 @@ contract EulerSwapProtocolFeeConfig is IEulerSwapProtocolFeeConfig, EVCUtil {
104109
fee = defaultFee;
105110
}
106111
}
112+
113+
/// @dev Ensures the admin is not a known sub-account, since they are not allowed
114+
function _validateAdminAddress(address addr) internal view {
115+
address owner = evc.getAccountOwner(addr);
116+
require(owner == addr || owner == address(0), InvalidAdminAddress());
117+
}
107118
}

test/Fees.t.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,20 @@ contract FeesTest is EulerSwapTestBase {
314314
}
315315

316316
function test_fees_protocolFees_setAdmin() public {
317+
// Register owner with EVC
318+
evc.enableCollateral(address(this), address(0));
319+
317320
address origAdmin = protocolFeeConfig.admin();
318321
assertEq(origAdmin, protocolFeeAdmin);
319322

320323
vm.expectRevert(EulerSwapProtocolFeeConfig.Unauthorized.selector);
321324
protocolFeeConfig.setDefault(address(8888), 0.1e18);
322325

326+
// Can't set a subaccount
327+
vm.expectRevert(EulerSwapProtocolFeeConfig.InvalidAdminAddress.selector);
328+
vm.prank(protocolFeeAdmin);
329+
protocolFeeConfig.setAdmin(address(uint160(address(this)) ^ 1));
330+
323331
vm.expectEmit(true, true, true, true);
324332
emit EulerSwapProtocolFeeConfig.AdminUpdated(origAdmin, address(this));
325333
vm.prank(protocolFeeAdmin);

0 commit comments

Comments
 (0)