Skip to content

Commit a8c516a

Browse files
committed
deployer guard fix
1 parent 4e6f4ec commit a8c516a

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

contracts/mock/utils/ERC20UpgradeableMock.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ pragma solidity ^0.8.21;
44

55
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
66

7-
import {DeployerGuard} from "../../utils/DeployerGuard.sol";
7+
import {ADeployerGuard} from "../../utils/ADeployerGuard.sol";
88

9-
contract ERC20UpgradeableMock is DeployerGuard, ERC20Upgradeable {
9+
contract ERC20UpgradeableMock is ADeployerGuard, ERC20Upgradeable {
1010
uint8 internal _decimals;
1111

12-
constructor() DeployerGuard(msg.sender) {}
12+
constructor() ADeployerGuard(msg.sender) {}
1313

1414
function __ERC20UpgradeableMock_init(
1515
string memory name_,

contracts/utils/ABlockGuard.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pragma solidity ^0.8.21;
1010
* ## Usage example:
1111
*
1212
* ```
13-
* contract NotFlashloanable is BlockGuard {
13+
* contract NotFlashloanable is ABlockGuard {
1414
* function deposit(uint256 amount) external lockBlock("DEPOSIT", msg.sender) {
1515
* . . .
1616
* }

contracts/utils/DeployerGuard.sol renamed to contracts/utils/ADeployerGuard.sol

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,40 @@ pragma solidity ^0.8.21;
33

44
/**
55
* @title DeployerGuard
6-
* @notice A utility contract that provides protected initialization capabilities for contracts
7-
* that depend on each other. This contract ensures that contracts are never left in an
8-
* unprotected state during deployment by allowing a second initialization phase that is
9-
* restricted to the deployer only.
6+
* @notice A utility contract that provides protected initialization capabilities for other contracts.
7+
*
8+
* Generally speaking, the common "Initializer" approach is easily front-runnable and shouldn't be used on its own.
9+
*
10+
* This simple utility ensures that contracts are never left in an unprotected state during deployment by
11+
* integrating a second validation step restricted to the deployer only.
12+
*
13+
* ## Usage example:
14+
*
15+
* ```
16+
* contract ProtectedImpl is ADeployerGuard {
17+
* constructor() ADeployerGuard(msg.sender) {}
18+
*
19+
* function __ERC20_init(
20+
* string memory name_,
21+
* string memory symbol_,
22+
* ) external initializer onlyDeployer {
23+
* __ERC20_init(name_, symbol_);
24+
* }
25+
* }
26+
* ```
1027
*/
11-
contract DeployerGuard {
28+
abstract contract ADeployerGuard {
1229
/// @notice The address of the contract deployer
13-
address private immutable __SOLARITY_GUARD_DEPLOYER;
30+
address private immutable _GUARD_DEPLOYER;
1431

1532
/// @notice Error thrown when a non-deployer address attempts to call deployer-only functions
1633
/// @param caller The address that attempted to call the function
1734
error OnlyDeployer(address caller);
1835

1936
/**
2037
* @dev Modifier that restricts function access to the deployer only
21-
* @notice This modifier should be used on second initialization functions
22-
* to ensure only the original deployer can establish cross-contract references
38+
* @notice This modifier should be used on the initialization functions
39+
* to ensure their non-frontrunability
2340
*/
2441
modifier onlyDeployer() {
2542
_requireDeployer(msg.sender);
@@ -30,7 +47,7 @@ contract DeployerGuard {
3047
* @dev Constructor that sets the deployer address
3148
*/
3249
constructor(address deployer_) {
33-
__SOLARITY_GUARD_DEPLOYER = deployer_;
50+
_GUARD_DEPLOYER = deployer_;
3451
}
3552

3653
/**
@@ -53,6 +70,6 @@ contract DeployerGuard {
5370
* @dev Internal function to get the deployer address
5471
*/
5572
function _deployer() internal view virtual returns (address) {
56-
return __SOLARITY_GUARD_DEPLOYER;
73+
return _GUARD_DEPLOYER;
5774
}
5875
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@solarity/solidity-lib",
3-
"version": "3.1.5",
3+
"version": "3.1.6",
44
"license": "MIT",
55
"author": "Distributed Lab",
66
"readme": "README.md",

0 commit comments

Comments
 (0)