Skip to content

Commit 80171e7

Browse files
committed
fix: create function admin parameter deleted
1 parent 58efe28 commit 80171e7

File tree

3 files changed

+181
-34
lines changed

3 files changed

+181
-34
lines changed

abis/ValidatorFactory.json

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@
4242
"type": "function",
4343
"name": "create",
4444
"inputs": [
45-
{
46-
"name": "admin",
47-
"type": "address",
48-
"internalType": "address"
49-
},
5045
{
5146
"name": "dealId",
5247
"type": "uint256",
@@ -112,18 +107,18 @@
112107
"name": "grantRole",
113108
"inputs": [
114109
{
115-
"name": "role",
110+
"name": "",
116111
"type": "bytes32",
117112
"internalType": "bytes32"
118113
},
119114
{
120-
"name": "account",
115+
"name": "",
121116
"type": "address",
122117
"internalType": "address"
123118
}
124119
],
125120
"outputs": [],
126-
"stateMutability": "nonpayable"
121+
"stateMutability": "pure"
127122
},
128123
{
129124
"type": "function",
@@ -242,30 +237,43 @@
242237
"name": "renounceRole",
243238
"inputs": [
244239
{
245-
"name": "role",
240+
"name": "",
246241
"type": "bytes32",
247242
"internalType": "bytes32"
248243
},
249244
{
250-
"name": "callerConfirmation",
245+
"name": "",
251246
"type": "address",
252247
"internalType": "address"
253248
}
254249
],
255250
"outputs": [],
256-
"stateMutability": "nonpayable"
251+
"stateMutability": "pure"
257252
},
258253
{
259254
"type": "function",
260255
"name": "revokeRole",
261256
"inputs": [
262257
{
263-
"name": "role",
258+
"name": "",
264259
"type": "bytes32",
265260
"internalType": "bytes32"
266261
},
267262
{
268-
"name": "account",
263+
"name": "",
264+
"type": "address",
265+
"internalType": "address"
266+
}
267+
],
268+
"outputs": [],
269+
"stateMutability": "pure"
270+
},
271+
{
272+
"type": "function",
273+
"name": "setAdmin",
274+
"inputs": [
275+
{
276+
"name": "newAdmin",
269277
"type": "address",
270278
"internalType": "address"
271279
}
@@ -310,6 +318,19 @@
310318
"outputs": [],
311319
"stateMutability": "payable"
312320
},
321+
{
322+
"type": "event",
323+
"name": "AdminChanged",
324+
"inputs": [
325+
{
326+
"name": "newAdmin",
327+
"type": "address",
328+
"indexed": true,
329+
"internalType": "address"
330+
}
331+
],
332+
"anonymous": false
333+
},
313334
{
314335
"type": "event",
315336
"name": "Initialized",
@@ -534,11 +555,21 @@
534555
"name": "InvalidFilecoinPayAddress",
535556
"inputs": []
536557
},
558+
{
559+
"type": "error",
560+
"name": "InvalidImplementationAddress",
561+
"inputs": []
562+
},
537563
{
538564
"type": "error",
539565
"name": "InvalidInitialization",
540566
"inputs": []
541567
},
568+
{
569+
"type": "error",
570+
"name": "InvalidNewAdminAddress",
571+
"inputs": []
572+
},
542573
{
543574
"type": "error",
544575
"name": "InvalidPoRepMarketAddress",
@@ -556,17 +587,17 @@
556587
},
557588
{
558589
"type": "error",
559-
"name": "InvalidSlcAddress",
590+
"name": "InvalidSliScorerAddress",
560591
"inputs": []
561592
},
562593
{
563594
"type": "error",
564-
"name": "InvalidSliScorerAddress",
595+
"name": "NotInitializing",
565596
"inputs": []
566597
},
567598
{
568599
"type": "error",
569-
"name": "NotInitializing",
600+
"name": "RoleManagementDisabled",
570601
"inputs": []
571602
},
572603
{

src/ValidatorFactory.sol

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ contract ValidatorFactory is UUPSUpgradeable, AccessControlUpgradeable {
3333
address _poRepMarket;
3434
address _SPRegistry;
3535
address _beacon;
36+
address _admin;
3637
}
3738

3839
// keccak256(abi.encode(uint256(keccak256("porepmarket.storage.ValidatorFactoryStorage")) - 1)) & ~bytes32(uint256(0xff))
@@ -59,13 +60,15 @@ contract ValidatorFactory is UUPSUpgradeable, AccessControlUpgradeable {
5960
error InstanceAlreadyExists();
6061
error InvalidAdminAddress();
6162
error InvalidClientAddress();
62-
error InvalidSlcAddress();
6363
error InvalidPoRepMarketAddress();
6464
error InvalidClientSmartContractAddress();
6565
error InvalidFilecoinPayAddress();
6666
error InvalidPoRepServiceAddress();
6767
error InvalidSliScorerAddress();
6868
error InvalidSPRegistryAddress();
69+
error InvalidImplementationAddress();
70+
error InvalidNewAdminAddress();
71+
error RoleManagementDisabled();
6972

7073
/**
7174
* @notice Emitted when a new proxy is successfully created
@@ -74,19 +77,33 @@ contract ValidatorFactory is UUPSUpgradeable, AccessControlUpgradeable {
7477
*/
7578
event ProxyCreated(address indexed proxy, uint256 indexed dealId);
7679

80+
/**
81+
* @notice Emitted when the admin is changed
82+
* @param newAdmin The address of the new admin
83+
*/
84+
event AdminChanged(address indexed newAdmin);
85+
7786
/**
7887
* @notice Initializes the contract
7988
* @dev Initializes the contract by setting a default admin role and a UUPS upgradeable role
8089
* @param admin The address of the admin responsible for the contract
8190
* @param implementation The address of the implementation contract
8291
*/
8392
function initialize(address admin, address implementation) public initializer {
93+
if (admin == address(0)) {
94+
revert InvalidAdminAddress();
95+
}
96+
if (implementation == address(0)) {
97+
revert InvalidImplementationAddress();
98+
}
99+
84100
__AccessControl_init();
85101
_grantRole(DEFAULT_ADMIN_ROLE, admin);
86102
_grantRole(UPGRADER_ROLE, admin);
87103

88104
ValidatorFactoryStorage storage $ = s();
89105
$._beacon = address(new UpgradeableBeacon(implementation, admin));
106+
$._admin = admin;
90107
}
91108

92109
/**
@@ -127,12 +144,9 @@ contract ValidatorFactory is UUPSUpgradeable, AccessControlUpgradeable {
127144
* @notice Creates a new instance of an upgradeable contract.
128145
* @dev Uses BeaconProxy to create a new proxy instance, pointing to the Beacon for the logic contract.
129146
* @dev Reverts if an instance for the given dealId already exists.
130-
* @param admin The address of the admin responsible for the contract.
131147
* @param dealId The dealId for which the proxy was created.
132148
*/
133-
function create(address admin, uint256 dealId) external {
134-
if (admin == address(0)) revert InvalidAdminAddress();
135-
149+
function create(uint256 dealId) external {
136150
ValidatorFactoryStorage storage $ = s();
137151
if ($._instances[dealId] != address(0)) revert InstanceAlreadyExists();
138152

@@ -146,7 +160,7 @@ contract ValidatorFactory is UUPSUpgradeable, AccessControlUpgradeable {
146160
abi.encodeCall(
147161
Validator.initialize,
148162
(
149-
admin,
163+
$._admin,
150164
$._poRepService,
151165
$._filecoinPay,
152166
$._sliScorer,
@@ -159,7 +173,7 @@ contract ValidatorFactory is UUPSUpgradeable, AccessControlUpgradeable {
159173
)
160174
);
161175
// forge-lint: disable-next-line(asm-keccak256)
162-
bytes32 salt = keccak256(abi.encode(admin, dealId));
176+
bytes32 salt = keccak256(abi.encode($._admin, dealId));
163177
address proxy = Create2.computeAddress(salt, keccak256(initCode), address(this));
164178
$._instances[dealId] = proxy;
165179
$._isValidatorContract[proxy] = true;
@@ -168,6 +182,51 @@ contract ValidatorFactory is UUPSUpgradeable, AccessControlUpgradeable {
168182
emit ProxyCreated(proxy, dealId);
169183
}
170184

185+
/**
186+
* @notice Sets a new admin for the contract and revoke the role from the old admin
187+
* @dev Only callable by the current admin. Reverts if the new admin address is the zero address.
188+
* @param newAdmin The new admin address
189+
*/
190+
function setAdmin(address newAdmin) external onlyRole(DEFAULT_ADMIN_ROLE) {
191+
if (newAdmin == address(0)) {
192+
revert InvalidNewAdminAddress();
193+
}
194+
ValidatorFactoryStorage storage $ = s();
195+
196+
_revokeRole(DEFAULT_ADMIN_ROLE, $._admin);
197+
_grantRole(DEFAULT_ADMIN_ROLE, newAdmin);
198+
$._admin = newAdmin;
199+
200+
emit AdminChanged(newAdmin);
201+
}
202+
203+
// solhint-disable use-natspec
204+
/**
205+
* @notice Disabled role management functions
206+
* @dev This contract has a fixed admin and does not allow for dynamic role management
207+
*/
208+
function grantRole(bytes32, address) public pure override {
209+
revert RoleManagementDisabled();
210+
}
211+
212+
/**
213+
* @notice Disabled role management functions
214+
* @dev This contract has a fixed admin and does not allow for dynamic role management
215+
*/
216+
function revokeRole(bytes32, address) public pure override {
217+
revert RoleManagementDisabled();
218+
}
219+
220+
/**
221+
* @notice Disabled role management functions
222+
* @dev This contract has a fixed admin and does not allow for dynamic role management
223+
*/
224+
function renounceRole(bytes32, address) public pure override {
225+
revert RoleManagementDisabled();
226+
}
227+
228+
// solhint-enable use-natspec
229+
171230
/**
172231
* @notice Checks if an address is a validator contract
173232
* @param contractAddress The address to check

0 commit comments

Comments
 (0)