Skip to content
Access control Audit finding Intermediate

OwnableSmartWallet: Multiple approvals can lead to unwanted ownership transfers

The smart wallet contract only revoked one approval when ownership changed, leaving other approvals active. An attacker could claim ownership later without the current owner's approval.

aphak5010 Follow

Originally disclosed on Code4rena

Submitted by aphak5010

https://github.com/code-423n4/2022-11-stakehouse/blob/4b6828e9c807f2f7c569e6d721ca1289f7cf7112/contracts/smart-wallet/OwnableSmartWallet.sol#L94 https://github.com/code-423n4/2022-11-stakehouse/blob/4b6828e9c807f2f7c569e6d721ca1289f7cf7112/contracts/smart-wallet/OwnableSmartWallet.sol#L105-L106

The OwnableSmartWallet contract employs a mechanism for the owner to approve addresses that can then claim ownership (https://github.com/code-423n4/2022-11-stakehouse/blob/4b6828e9c807f2f7c569e6d721ca1289f7cf7112/contracts/smart-wallet/OwnableSmartWallet.sol#L94) of the contract.

The source code has a comment included which states that “Approval is revoked, in order to avoid unintended transfer allowance if this wallet ever returns to the previous owner” (https://github.com/code-423n4/2022-11-stakehouse/blob/4b6828e9c807f2f7c569e6d721ca1289f7cf7112/contracts/smart-wallet/OwnableSmartWallet.sol#L105-L106).

This means that when ownership is transferred from User A to User B, the approvals that User A has given should be revoked.

The existing code does not however revoke all approvals that User A has given. It only revokes one approval.

This can lead to unwanted transfers of ownership.

Proof of Concept

  1. User A approves User B and User C to claim ownership
  2. User B claims ownership first
  3. Only User A’s approval for User B is revoked, not however User A’s approval for User C
  4. User B transfers ownerhsip back to User A
  5. Now User C can claim ownership even though this time User A has not approved User C

Tools Used

VSCode

Recommended Mitigation Steps

You should invalidate all approvals User A has given when another User becomes the owner of the OwnableSmartWallet.

Unfortunately you cannot use a statement like delete _isTransferApproved[owner()].

So you would need an array that keeps track of approvals as pointed out in this StackExchange question: https://ethereum.stackexchange.com/questions/15553/how-to-delete-a-mapping

vince0656 (Stakehouse) confirmed


The original report as published on Code4rena, by aphak5010. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the code only deleted the approval for the specific address that claimed ownership, instead of clearing all approvals given by the previous owner.

Impact

An address that was previously approved could claim ownership of the wallet without the current owner's consent, potentially leading to unwanted transfers.

What the attacker needed

Owner approves multiple addresses; one approved address claims ownership; ownership returns to original owner

The fix

The contract should invalidate all approvals given by the previous owner when ownership changes, for example by tracking approvals in an array and clearing them.

How it was found

  1. User A approves User B and User C to claim ownership
  2. User B claims ownership first
  3. Only User A’s approval for User B is revoked, not however User A’s approval for User C
  4. User B transfers ownerhsip back to User A
  5. Now User C can claim ownership even though this time User A has not approved User C

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A smart wallet lets its owner approve other addresses to take over ownership. The code was supposed to cancel all these approvals when ownership changed, but it only cancelled one. This meant an old approval could still be used later to take control without the new owner's permission.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by aphak5010

View all

6 more disclosed reports, best first.

More from LSD Network - Stakehouse contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.