Skip to content

Commit 052dc66

Browse files
authored
Merge pull request #67 from rocket-pool/contract-optimisations
Backup address fixes
2 parents ec3c5a2 + a6e3b92 commit 052dc66

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

contracts/RocketUser.sol

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ contract RocketUser is RocketBase {
174174
// Get an instance of that pool contract
175175
rocketPoolMini = RocketPoolMini(_miniPoolAddress);
176176
// Got the users address, now check to see if this is a user withdrawing to their backup address, if so, we need to update the users minipool account
177-
if (rocketPoolMini.getUserBackupAddressExists(_userAddress)) {
177+
if (!rocketPoolMini.getUserExists(_userAddress) && rocketPoolMini.getUserBackupAddressExists(_userAddress)) {
178178
// Get the original deposit address now
179179
// This will update the users account to match the backup address, but only after many checks and balances
180180
// It will fail if the user can't use their backup address to withdraw at this point or its not their nominated backup address trying
@@ -270,10 +270,17 @@ contract RocketUser is RocketBase {
270270
/// @param _miniPoolAddress The address of the mini pool they the supplied user account is in.
271271
/// @param _newUserAddressUsedForDeposit The address the user wishes to make their backup withdrawal address
272272
function userSetWithdrawalDepositAddress(address _newUserAddressUsedForDeposit, address _miniPoolAddress) public returns(bool) {
273+
// Check backup withdrawal address is valid
274+
require(_newUserAddressUsedForDeposit != 0);
273275
// Get an instance of that pool contract
274276
rocketPoolMini = RocketPoolMini(_miniPoolAddress);
277+
// Check user exists in minipool
278+
require(rocketPoolMini.getUserExists(msg.sender));
279+
// Check backup withdrawal address is not already in use
280+
require(!rocketPoolMini.getUserExists(_newUserAddressUsedForDeposit));
281+
require(!rocketPoolMini.getUserBackupAddressExists(_newUserAddressUsedForDeposit));
275282
// User can only set this backup address before deployment to casper, also partners cannot set this address to their own to prevent them accessing the users funds after the set withdrawal backup period expires
276-
if ((rocketPoolMini.getStatus() == 0 || rocketPoolMini.getStatus() == 1) && _newUserAddressUsedForDeposit != 0 && rocketPoolMini.getUserPartner(msg.sender) != _newUserAddressUsedForDeposit) {
283+
if ((rocketPoolMini.getStatus() == 0 || rocketPoolMini.getStatus() == 1) && rocketPoolMini.getUserPartner(msg.sender) != _newUserAddressUsedForDeposit) {
277284
if (rocketPoolMini.setUserAddressBackupWithdrawal(msg.sender, _newUserAddressUsedForDeposit)) {
278285
// Fire the event
279286
emit UserSetBackupWithdrawalAddress(msg.sender, _newUserAddressUsedForDeposit, _miniPoolAddress, now);

test/rocket-user/rocket-user-tests.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,20 +271,49 @@ export default function({owner}) {
271271

272272
// User cannot set a backup withdrawal address to an invalid address
273273
it(printTitle('user', 'cannot set a backup withdrawal address to an invalid address'), async () => {
274-
275-
// Register withdrawal address
276-
let result = await scenarioRegisterWithdrawalAddress({
274+
await assertThrows(scenarioRegisterWithdrawalAddress({
277275
withdrawalAddress: '0x0000000000000000000000000000000000000000',
278276
miniPool: miniPools.first,
279277
fromAddress: userFirst,
280278
gas: 550000,
281279
checkLogs: false,
282-
});
280+
}), 'Backup withdrawal address was set');
281+
});
282+
283+
284+
// User cannot set a backup withdrawal address to their deposit address
285+
it(printTitle('user', 'cannot set a backup withdrawal address to their deposit address'), async () => {
286+
await assertThrows(scenarioRegisterWithdrawalAddress({
287+
withdrawalAddress: userFirst,
288+
miniPool: miniPools.first,
289+
fromAddress: userFirst,
290+
gas: 550000,
291+
checkLogs: false,
292+
}), 'Backup withdrawal address was set');
293+
});
283294

284-
// Assert UserSetBackupWithdrawalAddress event was not logged
285-
let log = result.logs.find(({ event }) => event == 'UserSetBackupWithdrawalAddress');
286-
assert.equal(log, undefined, 'UserSetBackupWithdrawalAddress event was logged');
287295

296+
// User cannot set a backup withdrawal address to an existing deposit address
297+
it(printTitle('user', 'cannot set a backup withdrawal address to an existing deposit address'), async () => {
298+
await assertThrows(scenarioRegisterWithdrawalAddress({
299+
withdrawalAddress: userSecond,
300+
miniPool: miniPools.first,
301+
fromAddress: userFirst,
302+
gas: 550000,
303+
checkLogs: false,
304+
}), 'Backup withdrawal address was set');
305+
});
306+
307+
308+
// Random account cannot set a backup withdrawal address
309+
it(printTitle('random account', 'cannot set a backup withdrawal address'), async () => {
310+
await assertThrows(scenarioRegisterWithdrawalAddress({
311+
withdrawalAddress: userFirstBackupAddress,
312+
miniPool: miniPools.first,
313+
fromAddress: accounts[9],
314+
gas: 550000,
315+
checkLogs: false,
316+
}), 'Backup withdrawal address was set');
288317
});
289318

290319

0 commit comments

Comments
 (0)