Skip to content

Commit 11445d2

Browse files
committed
First draft of threat model
1 parent fff146c commit 11445d2

File tree

8 files changed

+530
-41
lines changed

8 files changed

+530
-41
lines changed

audits/staking/202506-threat-model-stake-holder.md

Lines changed: 321 additions & 0 deletions
Large diffs are not rendered by default.

script/staking/README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ The following variables must be specified for all scripts. They can be supplied
2020

2121
## Simple Deployment
2222

23-
To deploy the `StakeHolderERC20.sol` or the `StakeHolderWIMX.sol` contract with a `ERC1967Proxy.sol`, use the `deploySimple.sh` script.
23+
To deploy the `StakeHolderERC20V2.sol` or the `StakeHolderWIMXV2.sol` contract with a `ERC1967Proxy.sol`, use the `deploySimple.sh` script.
2424

2525
In addition to the common variables described above, the following variables must be specified via the environment or a `.env` file for the `deploySimple.sh` script:
2626

27-
* `DEPLOYER_ADDRESS`: Address that corresponds to the hardware wallet or private key. This account is used to deploy the `StakeHolderERC20` or `StakeHolderWIMX` and the `ERC1967Proxy` contracts.
27+
* `DEPLOYER_ADDRESS`: Address that corresponds to the hardware wallet or private key. This account is used to deploy the `StakeHolderERC20V2` or `StakeHolderWIMXV2` and the `ERC1967Proxy` contracts.
2828
* `ROLE_ADMIN`: Account that will be the initial role administrator. Accounts with the role administrator access can manage which accounts have `UPGRADE_ADMIN` and `DISTRIBUTED_ADMIN` access. Specify 0x0000000000000000000000000000000000000000 to have no account with role administrator access.
29-
* `UPGRADE_ADMIN`: Initial account that will be authorised to upgrade the StakeHolderERC20 contract. Specify 0x0000000000000000000000000000000000000000 to have no account with upgrade administrator access.
29+
* `UPGRADE_ADMIN`: Initial account that will be authorised to upgrade the StakeHolderERC20V2 contract. Specify 0x0000000000000000000000000000000000000000 to have no account with upgrade administrator access.
3030

3131
## Complex Deployment
3232

33-
To deploy the `StakeHolderERC20.sol` or the `StakeHolderWIMX.sol` contract with a `ERC1967Proxy.sol` and a `TimelockController` using an `OwnableCreate3Deployer`, use the `deployComplex.sh` script. If you do not have access to an `OwnableCreate3Deployer` contract, use the `deployDeployer.sh` script to deploy this contract first.
33+
To deploy the `StakeHolderERC20V2.sol` or the `StakeHolderWIMXV2.sol` contract with a `ERC1967Proxy.sol` and a `TimelockController` using an `OwnableCreate3Deployer`, use the `deployComplex.sh` script. If you do not have access to an `OwnableCreate3Deployer` contract, use the `deployDeployer.sh` script to deploy this contract first.
3434

3535
In addition to the common variables described above, the following variables must be specified via the environment or a `.env` file for the `deployDeployer.sh` script:
3636

@@ -52,3 +52,12 @@ The `stake.sh` script can be called to stake tokens and the `unstake.sh` script
5252
* `STAKE_HOLDER_CONTRACT`: The address of the deployed stake holder contract.
5353
* `STAKER_ADDRESS`: The address of the staker. The address corresponds to the hardware wallet or the private key.
5454
* `STAKER_AMOUNT`: The number of tokens. Note that the number of decimal places must be taken into account. For example, 1 IMX would be 1000000000000000000.
55+
56+
## Upgrading StakeHolderWIMX to StakeHolderWIMXV2 on MainNet
57+
58+
The following scripts are used as part of the process for upgrading the staking contract used on Immutable zkEVM Mainnet.
59+
60+
* `upgradeToWIMXV2_Deploy.sh`: Deploys `StakeHolderWIMXV2` using the `OwnableCreate3Deployer`. No additional environment variables need to be set to run this script.
61+
* `upgradeToWIMXV2_Propose.sh`: Proposes the upgrade to the TimelockController contract. Once the `StakeHolderWIMXV2` contract has been deployed, update the value of the `STAKE_HOLDER_V2` constant in `StakeHolderScriptWIMX.t.sol` to reflect the deployed address. Temporarily
62+
update `common.sh`, removing the `--broadcast` line. This will log the calldata, but not execute the transaction. Submit the calldata to Safe wallet.
63+
* `upgradeToWIMXV2_Execute.sh`: Executes the upgrade using the TimelockController contract. Once one week has elapsed, the upgrade can be executed. Temporarily update `common.sh`, removing the `--broadcast` line. This will log the calldata, but not execute the transaction. Submit the calldata to Safe wallet.

script/staking/StakeHolderScriptERC20.t.sol

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {ERC20PresetFixedSupply} from "openzeppelin-contracts-4.9.3/token/ERC20/p
99
import {IERC20} from "openzeppelin-contracts-4.9.3/token/ERC20/IERC20.sol";
1010

1111
import {IStakeHolder} from "../../contracts/staking/IStakeHolder.sol";
12-
import {StakeHolderERC20} from "../../contracts/staking/StakeHolderERC20.sol";
12+
import {StakeHolderERC20V2} from "../../contracts/staking/StakeHolderERC20V2.sol";
1313
import {OwnableCreate3Deployer} from "../../contracts/deployer/create3/OwnableCreate3Deployer.sol";
1414

1515
/**
@@ -77,7 +77,7 @@ contract StakeHolderScriptERC20 is Test {
7777
}
7878

7979
/**
80-
* Deploy StakeHolderERC20 using Create3, with the TimelockController.
80+
* Deploy StakeHolderERC20V2 using Create3, with the TimelockController.
8181
*/
8282
function deployComplex() external {
8383
address signer = vm.envAddress("DEPLOYER_ADDRESS");
@@ -100,7 +100,7 @@ contract StakeHolderScriptERC20 is Test {
100100
}
101101

102102
/**
103-
* Deploy StakeHolderERC20 using an EOA.
103+
* Deploy StakeHolderERC20V2 using an EOA.
104104
*/
105105
function deploySimple() external {
106106
address deployer = vm.envAddress("DEPLOYER_ADDRESS");
@@ -145,14 +145,14 @@ contract StakeHolderScriptERC20 is Test {
145145
}
146146

147147
/**
148-
* Deploy StakeHolderERC20 using Create3, with the TimelockController.
148+
* Deploy StakeHolderERC20V2 using Create3, with the TimelockController.
149149
*/
150150
function _deployComplex(
151151
ComplexDeploymentArgs memory deploymentArgs,
152152
ComplexStakeHolderContractArgs memory stakeHolderArgs,
153153
ComplexTimelockContractArgs memory timelockArgs)
154154
private
155-
returns (StakeHolderERC20 stakeHolderContract, TimelockController timelockController)
155+
returns (StakeHolderERC20V2 stakeHolderContract, TimelockController timelockController)
156156
{
157157
IDeployer ownableCreate3 = IDeployer(deploymentArgs.factory);
158158

@@ -185,10 +185,10 @@ contract StakeHolderScriptERC20 is Test {
185185
}
186186

187187

188-
// Deploy StakeHolderERC20 via the Ownable Create3 factory.
188+
// Deploy StakeHolderERC20V2 via the Ownable Create3 factory.
189189
// Create deployment bytecode and encode constructor args
190190
deploymentBytecode = abi.encodePacked(
191-
type(StakeHolderERC20).creationCode
191+
type(StakeHolderERC20V2).creationCode
192192
);
193193
/// @dev Deploy the contract via the Ownable CREATE3 factory
194194
vm.startBroadcast(deploymentArgs.signer);
@@ -198,7 +198,7 @@ contract StakeHolderScriptERC20 is Test {
198198
// Deploy ERC1967Proxy via the Ownable Create3 factory.
199199
// Create init data for the ERC1967 Proxy
200200
bytes memory initData = abi.encodeWithSelector(
201-
StakeHolderERC20.initialize.selector,
201+
StakeHolderERC20V2.initialize.selector,
202202
timelockAddress, // roleAdmin
203203
timelockAddress, // upgradeAdmin
204204
stakeHolderArgs.distributeAdmin,
@@ -214,34 +214,34 @@ contract StakeHolderScriptERC20 is Test {
214214
address stakeHolderContractAddress = ownableCreate3.deploy(deploymentBytecode, salt3);
215215
vm.stopBroadcast();
216216

217-
stakeHolderContract = StakeHolderERC20(stakeHolderContractAddress);
217+
stakeHolderContract = StakeHolderERC20V2(stakeHolderContractAddress);
218218
timelockController = TimelockController(payable(timelockAddress));
219219
}
220220

221221
/**
222-
* Deploy StakeHolderERC20 using an EOA and no time lock.
222+
* Deploy StakeHolderERC20V2 using an EOA and no time lock.
223223
*/
224224
function _deploySimple(
225225
SimpleDeploymentArgs memory deploymentArgs,
226226
SimpleStakeHolderContractArgs memory stakeHolderArgs)
227227
private
228-
returns (StakeHolderERC20 stakeHolderContract) {
228+
returns (StakeHolderERC20V2 stakeHolderContract) {
229229

230230
bytes memory initData = abi.encodeWithSelector(
231-
StakeHolderERC20.initialize.selector,
231+
StakeHolderERC20V2.initialize.selector,
232232
stakeHolderArgs.roleAdmin,
233233
stakeHolderArgs.upgradeAdmin,
234234
stakeHolderArgs.distributeAdmin,
235235
stakeHolderArgs.token);
236236

237237
vm.startBroadcast(deploymentArgs.deployer);
238-
StakeHolderERC20 impl = new StakeHolderERC20();
238+
StakeHolderERC20V2 impl = new StakeHolderERC20V2();
239239
vm.stopBroadcast();
240240
vm.startBroadcast(deploymentArgs.deployer);
241241
ERC1967Proxy proxy = new ERC1967Proxy(address(impl), initData);
242242
vm.stopBroadcast();
243243

244-
stakeHolderContract = StakeHolderERC20(address(proxy));
244+
stakeHolderContract = StakeHolderERC20V2(address(proxy));
245245
}
246246

247247
function _stake(IStakeHolder _stakeHolder, address _staker, uint256 _amount) private {
@@ -306,7 +306,7 @@ contract StakeHolderScriptERC20 is Test {
306306
});
307307

308308
// Run deployment against forked testnet
309-
StakeHolderERC20 stakeHolder;
309+
StakeHolderERC20V2 stakeHolder;
310310
TimelockController timelockController;
311311
(stakeHolder, timelockController) =
312312
_deployComplex(deploymentArgs, stakeHolderArgs, timelockArgs);
@@ -350,7 +350,7 @@ contract StakeHolderScriptERC20 is Test {
350350
});
351351

352352
// Run deployment against forked testnet
353-
StakeHolderERC20 stakeHolder = _deploySimple(deploymentArgs, stakeHolderContractArgs);
353+
StakeHolderERC20V2 stakeHolder = _deploySimple(deploymentArgs, stakeHolderContractArgs);
354354

355355
_commonTest(false, IStakeHolder(stakeHolder), address(0),
356356
bank, deployer, roleAdmin, upgradeAdmin, distributeAdmin);
@@ -374,7 +374,7 @@ contract StakeHolderScriptERC20 is Test {
374374

375375
// Post deployment checks
376376
{
377-
StakeHolderERC20 temp = new StakeHolderERC20();
377+
StakeHolderERC20V2 temp = new StakeHolderERC20V2();
378378
bytes32 defaultAdminRole = temp.DEFAULT_ADMIN_ROLE();
379379
assertTrue(_stakeHolder.hasRole(_stakeHolder.UPGRADE_ROLE(), upgradeAdmin), "Upgrade admin should have upgrade role");
380380
assertTrue(_stakeHolder.hasRole(defaultAdminRole, roleAdmin), "Role admin should have default admin role");

0 commit comments

Comments
 (0)