Skip to content

Commit

Permalink
Fixing BRA-01 from CertiK audit
Browse files Browse the repository at this point in the history
  • Loading branch information
eloi010 committed Dec 18, 2023
1 parent b9e652d commit d38d49c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/core/base/BaseRecoverableAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ abstract contract BaseRecoverableAccount is BaseOpenfortAccount, Ownable2StepUpg
function proposeGuardian(address _guardian) external onlyOwner {
if (isLocked()) revert AccountLocked();
if (owner() == _guardian) revert GuardianCannotBeOwner();
if (pendingOwner() == _guardian) revert GuardianCannotBeOwner();
if (isGuardian(_guardian)) revert DuplicatedGuardian();
if (_guardian == address(0)) revert ZeroAddressNotAllowed();

Expand Down
24 changes: 24 additions & 0 deletions test/foundry/core/managed/ManagedOpenfortAccountTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2506,4 +2506,28 @@ contract ManagedOpenfortAccountTest is OpenfortBaseTest {
assertTrue(account.supportsInterface(type(IERC165).interfaceId));
assertFalse(account.supportsInterface(bytes4(0x0000)));
}

/*
* Testcase where a pending owner is proposed as guardian. It used to work, should fail now.
* From the CertiK audit, issue BRA-01
*/
function testFailAddPendingOwnerAsGuardian() public {
ManagedOpenfortAccount openfortAccount = ManagedOpenfortAccount(payable(accountAddress));

address newOwner = makeAddr("newOwner");
vm.prank(openfortAdmin);
openfortAccount.transferOwnership(newOwner);

vm.prank(openfortAdmin);
openfortAccount.proposeGuardian(newOwner);

skip(SECURITY_PERIOD);
openfortAccount.confirmGuardianProposal(newOwner);

vm.prank(newOwner);
openfortAccount.acceptOwnership();

assertEq(openfortAccount.isGuardian(newOwner), true);
assertEq(openfortAccount.owner(), newOwner);
}
}
24 changes: 24 additions & 0 deletions test/foundry/core/upgradeable/UpgradeableOpenfortAccountTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2844,4 +2844,28 @@ contract UpgradeableOpenfortAccountTest is OpenfortBaseTest {
vm.prank(openfortAdmin);
openfortFactory.updateInitialGuardian(address(openfortAdmin));
}

/*
* Testcase where a pending owner is proposed as guardian. It used to work, should fail now.
* From the CertiK audit, issue BRA-01
*/
function testFailAddPendingOwnerAsGuardian() public {
IBaseRecoverableAccount openfortAccount = IBaseRecoverableAccount(payable(accountAddress));

address newOwner = makeAddr("newOwner");
vm.prank(openfortAdmin);
openfortAccount.transferOwnership(newOwner);

vm.prank(openfortAdmin);
openfortAccount.proposeGuardian(newOwner);

skip(SECURITY_PERIOD);
openfortAccount.confirmGuardianProposal(newOwner);

vm.prank(newOwner);
openfortAccount.acceptOwnership();

assertEq(openfortAccount.isGuardian(newOwner), true);
assertEq(openfortAccount.owner(), newOwner);
}
}

0 comments on commit d38d49c

Please sign in to comment.