Skip to content

Commit 39c1655

Browse files
authored
Update ERC7947 interface (#154)
* Update ERC7947 interface * Fix unit tests
1 parent 5dc1097 commit 39c1655

File tree

8 files changed

+60
-63
lines changed

8 files changed

+60
-63
lines changed

contracts/account-abstraction/AAccountRecovery.sol

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {IRecoveryProvider} from "../interfaces/account-abstraction/IRecoveryProv
1313
* You may use this module as a base contract for your own account recovery mechanism.
1414
*
1515
* The Account Recovery module allows to add recovery providers to the account.
16-
* The recovery providers are used to recover the account ownership.
16+
* The recovery providers are used to recover the account access.
1717
*
1818
* For more information please refer to [EIP-7947](https://eips.ethereum.org/EIPS/eip-7947).
1919
*/
@@ -35,20 +35,23 @@ abstract contract AAccountRecovery is IAccountRecovery {
3535
/**
3636
* @inheritdoc IAccountRecovery
3737
*/
38-
function addRecoveryProvider(address provider_, bytes memory recoveryData_) external virtual;
38+
function addRecoveryProvider(
39+
address provider_,
40+
bytes memory recoveryData_
41+
) external payable virtual;
3942

4043
/**
4144
* @inheritdoc IAccountRecovery
4245
*/
43-
function removeRecoveryProvider(address provider_) external virtual;
46+
function removeRecoveryProvider(address provider_) external payable virtual;
4447

4548
/**
4649
* @inheritdoc IAccountRecovery
4750
*/
48-
function recoverOwnership(
49-
address newOwner,
50-
address provider,
51-
bytes memory proof
51+
function recoverAccess(
52+
bytes memory subject_,
53+
address provider_,
54+
bytes memory proof_
5255
) external virtual returns (bool);
5356

5457
/**
@@ -99,20 +102,18 @@ abstract contract AAccountRecovery is IAccountRecovery {
99102
}
100103

101104
/**
102-
* @notice Should be called in the `recoverOwnership` function before updating the account owner
105+
* @notice Should be called in the `recoverAccess` function before updating the account access
103106
*/
104107
function _validateRecovery(
105-
address newOwner_,
108+
bytes memory object_,
106109
address provider_,
107110
bytes memory proof_
108111
) internal virtual {
109-
if (newOwner_ == address(0)) revert ZeroAddress();
110-
111112
AAccountRecoveryStorage storage $ = _getAAccountRecoveryStorage();
112113

113114
if (!$.recoveryProviders.contains(provider_)) revert ProviderNotRegistered(provider_);
114115

115-
IRecoveryProvider(provider_).recover(newOwner_, proof_);
116+
IRecoveryProvider(provider_).recover(object_, proof_);
116117
}
117118

118119
/**

contracts/interfaces/account-abstraction/IAccountRecovery.sol

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,38 @@ pragma solidity ^0.8.21;
99
* For more information please refer to [EIP-7947](https://eips.ethereum.org/EIPS/eip-7947).
1010
*/
1111
interface IAccountRecovery {
12-
event OwnershipRecovered(address indexed oldOwner, address indexed newOwner);
12+
event AccessRecovered(bytes subject);
1313
event RecoveryProviderAdded(address indexed provider);
1414
event RecoveryProviderRemoved(address indexed provider);
1515

1616
/**
1717
* @notice A function to add a new recovery provider.
1818
* SHOULD be access controlled.
1919
*
20-
* @param provider the address of a recovery provider (ZKP verifier) to add.
21-
* @param recoveryData custom data (commitment) for the recovery provider.
20+
* @param provider_ the address of a recovery provider (ZKP verifier) to add.
21+
* @param recoveryData_ custom data (commitment) for the recovery provider.
2222
*/
23-
function addRecoveryProvider(address provider, bytes memory recoveryData) external;
23+
function addRecoveryProvider(address provider_, bytes memory recoveryData_) external payable;
2424

2525
/**
2626
* @notice A function to remove an existing recovery provider.
2727
* SHOULD be access controlled.
2828
*
29-
* @param provider the address of a previously added recovery provider to remove.
29+
* @param provider_ the address of a previously added recovery provider to remove.
3030
*/
31-
function removeRecoveryProvider(address provider) external;
31+
function removeRecoveryProvider(address provider_) external payable;
3232

3333
/**
34-
* @notice A non-view function to recover ownership of a smart account.
35-
* @param newOwner the address of a new owner.
36-
* @param provider the address of a recovery provider.
37-
* @param proof an encoded proof of recovery (ZKP/ZKAI, signature, etc).
34+
* @notice A non-view function to recover access of a smart account.
35+
* @param subject_ the recovery subject (encoded owner address, access control role, etc).
36+
* @param provider_ the address of a recovery provider.
37+
* @param proof_ an encoded proof of recovery (ZKP/ZKAI, signature, etc).
3838
* @return `true` if recovery is successful, `false` (or revert) otherwise.
3939
*/
40-
function recoverOwnership(
41-
address newOwner,
42-
address provider,
43-
bytes memory proof
40+
function recoverAccess(
41+
bytes memory subject_,
42+
address provider_,
43+
bytes memory proof_
4444
) external returns (bool);
4545

4646
/**

contracts/interfaces/account-abstraction/IRecoveryProvider.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@ interface IRecoveryProvider {
1616
* @notice A function that "subscribes" a smart account (msg.sender) to a recovery provider.
1717
* SHOULD process and assign the `recoveryData` to the `msg.sender`.
1818
*
19-
* @param recoveryData a recovery commitment (hash/ZKP public output) to be used
19+
* @param recoveryData_ a recovery commitment (hash/ZKP public output) to be used
2020
* in the `recover` function to check a recovery proof validity.
2121
*/
22-
function subscribe(bytes memory recoveryData) external;
22+
function subscribe(bytes memory recoveryData_) external payable;
2323

2424
/**
2525
* @notice A function that revokes a smart account subscription.
2626
*/
27-
function unsubscribe() external;
27+
function unsubscribe() external payable;
2828

2929
/**
3030
* @notice A function that checks if a recovery of a smart account (msg.sender)
3131
* to the `newOwner` is possible.
3232
* SHOULD use `msg.sender`'s `recoveryData` to check the `proof` validity.
3333
*
34-
* @param newOwner the new owner to recover the `msg.sender` ownership to.
35-
* @param proof the recovery proof.
34+
* @param object_ the new object (may be different to subject) to recover the `msg.sender` access to.
35+
* @param proof_ the recovery proof.
3636
*/
37-
function recover(address newOwner, bytes memory proof) external;
37+
function recover(bytes memory object_, bytes memory proof_) external;
3838

3939
/**
4040
* @notice A function to get a recovery data (commitment) of an account.
4141
*
42-
* @param account the account to get the recovery data of.
42+
* @param account_ the account to get the recovery data of.
4343
* @return the associated recovery data.
4444
*/
45-
function getRecoveryData(address account) external view returns (bytes memory);
45+
function getRecoveryData(address account_) external view returns (bytes memory);
4646
}

contracts/mock/account-abstraction/AccountRecoveryMock.sol

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,27 @@ pragma solidity ^0.8.21;
44
import {AAccountRecovery} from "../../account-abstraction/AAccountRecovery.sol";
55

66
contract AccountRecoveryMock is AAccountRecovery {
7-
function addRecoveryProvider(address provider_, bytes memory recoveryData_) external override {
7+
function addRecoveryProvider(
8+
address provider_,
9+
bytes memory recoveryData_
10+
) external payable override {
811
_addRecoveryProvider(provider_, recoveryData_);
912
}
1013

11-
function removeRecoveryProvider(address provider_) external override {
14+
function removeRecoveryProvider(address provider_) external payable override {
1215
_removeRecoveryProvider(provider_);
1316
}
1417

15-
function validateRecovery(address newOwner_, address provider_, bytes memory proof_) external {
16-
_validateRecovery(newOwner_, provider_, proof_);
18+
function validateRecovery(
19+
bytes memory object_,
20+
address provider_,
21+
bytes memory proof_
22+
) external {
23+
_validateRecovery(object_, provider_, proof_);
1724
}
1825

19-
function recoverOwnership(
20-
address,
26+
function recoverAccess(
27+
bytes memory,
2128
address,
2229
bytes memory
2330
) external pure override returns (bool) {}

contracts/mock/account-abstraction/RecoveryProviderMock.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ pragma solidity ^0.8.21;
44
contract RecoveryProviderMock {
55
event SubscribeCalled(bytes recoveryData_);
66
event UnsubscribeCalled();
7-
event RecoverCalled(address newOwner, bytes proof);
7+
event RecoverCalled(bytes object, bytes proof);
88

9-
function subscribe(bytes memory recoveryData_) external {
9+
function subscribe(bytes memory recoveryData_) external payable {
1010
emit SubscribeCalled(recoveryData_);
1111
}
1212

13-
function unsubscribe() external {
13+
function unsubscribe() external payable {
1414
emit UnsubscribeCalled();
1515
}
1616

17-
function recover(address newOwner_, bytes memory proof_) external {
18-
emit RecoverCalled(newOwner_, proof_);
17+
function recover(bytes memory object_, bytes memory proof_) external {
18+
emit RecoverCalled(object_, proof_);
1919
}
2020
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@solarity/solidity-lib",
3-
"version": "3.1.6",
3+
"version": "3.1.7",
44
"license": "MIT",
55
"author": "Distributed Lab",
66
"readme": "README.md",

test/account-abstraction/AccountRecovery.test.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
import { expect } from "chai";
22
import { ethers } from "hardhat";
33

4-
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
5-
64
import { AccountRecoveryMock, RecoveryProviderMock } from "@/generated-types/ethers";
75
import { Reverter } from "@/test/helpers/reverter";
86

97
describe("AccountRecovery", () => {
108
const reverter = new Reverter();
119

12-
let OWNER: SignerWithAddress;
13-
1410
let accountRecovery: AccountRecoveryMock;
1511
let provider1: RecoveryProviderMock;
1612
let provider2: RecoveryProviderMock;
1713

14+
const OBJECT_DATA = "0x5678";
1815
const RECOVERY_DATA = "0x1234";
1916

2017
before(async () => {
21-
[OWNER] = await ethers.getSigners();
22-
2318
const AccountRecoveryMock = await ethers.getContractFactory("AccountRecoveryMock");
2419
accountRecovery = await AccountRecoveryMock.deploy();
2520

@@ -93,21 +88,15 @@ describe("AccountRecovery", () => {
9388
});
9489

9590
it("should call a `recover` function of a recovery provider", async () => {
96-
const tx = await accountRecovery.validateRecovery(OWNER, provider1, RECOVERY_DATA);
97-
await expect(tx).to.emit(provider1, "RecoverCalled").withArgs(OWNER, RECOVERY_DATA);
91+
const tx = await accountRecovery.validateRecovery(OBJECT_DATA, provider1, RECOVERY_DATA);
92+
await expect(tx).to.emit(provider1, "RecoverCalled").withArgs(OBJECT_DATA, RECOVERY_DATA);
9893
});
9994

10095
it("should revert if a provider is not added", async () => {
101-
await expect(accountRecovery.validateRecovery(OWNER, provider2, RECOVERY_DATA))
96+
await expect(accountRecovery.validateRecovery(OBJECT_DATA, provider2, RECOVERY_DATA))
10297
.to.be.revertedWithCustomError(accountRecovery, "ProviderNotRegistered")
10398
.withArgs(provider2);
10499
});
105-
106-
it("should revert if a new owner is zero address", async () => {
107-
await expect(
108-
accountRecovery.validateRecovery(ethers.ZeroAddress, provider1, RECOVERY_DATA),
109-
).to.be.revertedWithCustomError(accountRecovery, "ZeroAddress");
110-
});
111100
});
112101

113102
describe("recoveryProviderAdded", () => {

0 commit comments

Comments
 (0)