Skip to content

Commit

Permalink
Further fixing BRA-01 from CertiK audit
Browse files Browse the repository at this point in the history
  • Loading branch information
eloi010 committed Dec 22, 2023
1 parent d72d7a6 commit 42724b8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions contracts/core/base/BaseRecoverableAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ abstract contract BaseRecoverableAccount is BaseOpenfortAccount, Ownable2StepUpg
function transferOwnership(address _newOwner) public override {
if (isLocked()) revert AccountLocked();
if (isGuardian(_newOwner)) revert GuardianCannotBeOwner();
if (
guardiansConfig.info[_newOwner].pending != 0
&& block.timestamp <= guardiansConfig.info[_newOwner].pending + securityWindow
) {
revert GuardianCannotBeOwner();
}
super.transferOwnership(_newOwner);
}

Expand Down
25 changes: 24 additions & 1 deletion test/foundry/core/managed/ManagedOpenfortAccountTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2524,7 +2524,7 @@ contract ManagedOpenfortAccountTest is OpenfortBaseTest {
* 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 {
function testFailAddPendingOwnerAsGuardian1() public {
ManagedOpenfortAccount openfortAccount = ManagedOpenfortAccount(payable(accountAddress));

address newOwner = makeAddr("newOwner");
Expand All @@ -2543,4 +2543,27 @@ contract ManagedOpenfortAccountTest is OpenfortBaseTest {
assertEq(openfortAccount.isGuardian(newOwner), true);
assertEq(openfortAccount.owner(), newOwner);
}

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

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

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

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

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

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

0 comments on commit 42724b8

Please sign in to comment.