Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clean up unused code #207

Merged
merged 17 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ node_modules/

# era-test-node
era_test_node.log
anvil-zksync.log

package-lock.json
yarn.lock
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Forked from [Clave](https://github.com/getclave/clave-contracts).

1. Install workspace dependencies with `pnpm install`.
2. Install the latest release of
[Era Test Node](https://github.com/matter-labs/era-test-node).
[Era Test Node](https://github.com/matter-labs/anvil-zksync).
3. Run `pnpm build` to build the contracts.
4. Run `era_test_node run` and `pnpm test` in separate terminals to run the
tests.
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"eslint-plugin-simple-import-sort": "12.1.1",
"ethers": "6.13.2",
"globals": "15.9.0",
"hardhat": "^2.22.12",
"hardhat": "^2.22.17",
"husky": "9.1.6",
"ini": "5.0.0",
"lint-staged": "15.2.10",
Expand All @@ -74,14 +74,14 @@
"nx": "19.8.6",
"prettier": "3.3.3",
"prettier-plugin-solidity": "^1.4.1",
"solady": "^0.0.273",
"ts-node": "10.9.2",
"typechain": "8.3.2",
"typescript": "5.6.2",
"typescript-eslint": "8.7.0",
"viem": "^2.21.14",
"zksync-ethers": "6.15.0",
"zksync-sso": "0.0.0-beta.2",
"solady": "^0.0.273"
"zksync-sso": "0.0.0-beta.2"
},
"packageManager": "[email protected]"
}
162 changes: 81 additions & 81 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions src/AAFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ contract AAFactory is UpgradeableBeacon {
/// @param _salt The salt used for the `create2` deployment to make the address deterministic.
/// @param _uniqueAccountId A unique identifier for the new account.
/// @param _initialValidators An array of initial validators for the new account.
/// @param _initialModules An array of initial modules to be added to the new account.
/// @param _initialK1Owners An array of initial owners of the K1 key for the new account.
/// @return accountAddress The address of the newly deployed SSO account.
function deployProxySsoAccount(
bytes32 _salt,
string calldata _uniqueAccountId,
bytes[] calldata _initialValidators,
bytes[] calldata _initialModules,
bytes[] calldata _initialHooks,
address[] calldata _initialK1Owners
) external returns (address accountAddress) {
require(accountMappings[_uniqueAccountId] == address(0), "Account already exists");
Expand All @@ -64,8 +63,8 @@ contract AAFactory is UpgradeableBeacon {
require(success, "Deployment failed");
(accountAddress) = abi.decode(returnData, (address));

// Initialize the newly deployed account with validators, modules, and K1 owners.
ISsoAccount(accountAddress).initialize(_initialValidators, _initialModules, _initialK1Owners);
// Initialize the newly deployed account with validators, hooks and K1 owners.
ISsoAccount(accountAddress).initialize(_initialValidators, _initialHooks, _initialK1Owners);

accountMappings[_uniqueAccountId] = accountAddress;

Expand Down
23 changes: 7 additions & 16 deletions src/SsoAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Utils } from "@matterlabs/zksync-contracts/l2/system-contracts/librarie
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

import { HookManager } from "./managers/HookManager.sol";
import { ModuleManager } from "./managers/ModuleManager.sol";

import { TokenCallbackHandler, IERC165 } from "./helpers/TokenCallbackHandler.sol";

Expand All @@ -30,15 +29,7 @@ import { ISsoAccount } from "./interfaces/ISsoAccount.sol";
/// @notice This contract is a modular and extensible account implementation with support of
/// multi-ownership, custom modules, validation/execution hooks and different signature validation formats.
/// @dev Contract is expected to be used as Beacon proxy implementation.
contract SsoAccount is
Initializable,
HookManager,
ModuleManager,
ERC1271Handler,
TokenCallbackHandler,
BatchCaller,
ISsoAccount
{
contract SsoAccount is Initializable, HookManager, ERC1271Handler, TokenCallbackHandler, BatchCaller, ISsoAccount {
// Helper library for the Transaction struct
using TransactionHelper for Transaction;

Expand All @@ -50,21 +41,21 @@ contract SsoAccount is
/// @dev Sets passkey and passkey validator within account storage
/// @param _initialValidators An array of module validator addresses and initial validation keys
/// in an ABI encoded format of `abi.encode(validatorAddr,validationKey))`.
/// @param _initialModules An array of native module addresses and their initialize data
/// in an ABI encoded format of `abi.encode(moduleAddr,initData))`.
/// @param _initialValidationHooks An array of hook module validator addresses and initial validation keys
/// in an ABI encoded format of `abi.encode(validatorAddr,validationKey))`.
/// @param _initialK1Owners An array of addresses with full control over the account.
function initialize(
bytes[] calldata _initialValidators,
bytes[] calldata _initialModules,
bytes[] calldata _initialValidationHooks,
address[] calldata _initialK1Owners
) external initializer {
for (uint256 i = 0; i < _initialValidators.length; ++i) {
(address validatorAddr, bytes memory validationKey) = abi.decode(_initialValidators[i], (address, bytes));
_addModuleValidator(validatorAddr, validationKey);
}
for (uint256 i = 0; i < _initialModules.length; ++i) {
(address moduleAddr, bytes memory initData) = abi.decode(_initialModules[i], (address, bytes));
_addNativeModule(moduleAddr, initData);
for (uint256 i = 0; i < _initialValidationHooks.length; ++i) {
(address validatorAddr, bytes memory validationKey) = abi.decode(_initialValidationHooks[i], (address, bytes));
_installHook(validatorAddr, validationKey, true);
}
for (uint256 i = 0; i < _initialK1Owners.length; ++i) {
_k1AddOwner(_initialK1Owners[i]);
Expand Down
10 changes: 1 addition & 9 deletions src/auth/Auth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.24;

import { BootloaderAuth } from "./BootloaderAuth.sol";
import { ModuleAuth } from "./ModuleAuth.sol";
import { SelfAuth } from "./SelfAuth.sol";
import { HookAuth } from "./HookAuth.sol";
import { Errors } from "../libraries/Errors.sol";
Expand All @@ -12,11 +11,4 @@ import { Errors } from "../libraries/Errors.sol";
* @notice Abstract contract that organizes authentication logic for the contract
* @author https://getclave.io
*/
abstract contract Auth is BootloaderAuth, SelfAuth, ModuleAuth, HookAuth {
modifier onlySelfOrModule() {
if (msg.sender != address(this) && !_isModule(msg.sender)) {
revert Errors.NOT_FROM_SELF_OR_MODULE();
}
_;
}
}
abstract contract Auth is BootloaderAuth, SelfAuth, HookAuth {}
20 changes: 0 additions & 20 deletions src/auth/ModuleAuth.sol

This file was deleted.

27 changes: 1 addition & 26 deletions src/handlers/ValidationHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { BytesLinkedList } from "../libraries/LinkedList.sol";
import { OwnerManager } from "../managers/OwnerManager.sol";
import { ValidatorManager } from "../managers/ValidatorManager.sol";

import { IK1Validator, IR1Validator } from "../interfaces/IValidator.sol";
import { IModuleValidator } from "../interfaces/IModuleValidator.sol";

/**
Expand All @@ -20,31 +19,7 @@ abstract contract ValidationHandler is OwnerManager, ValidatorManager {
bytes32 signedHash,
bytes memory signature
) internal view returns (bool) {
if (_r1IsValidator(validator)) {
mapping(bytes => bytes) storage owners = OwnerManager._r1OwnersLinkedList();
bytes memory cursor = owners[BytesLinkedList.SENTINEL_BYTES];
while (cursor.length > BytesLinkedList.SENTINEL_LENGTH) {
bytes32[2] memory pubKey = abi.decode(cursor, (bytes32[2]));

bool _success = IR1Validator(validator).validateSignature(signedHash, signature, pubKey);

if (_success) {
return true;
}

cursor = owners[cursor];
}
} else if (_k1IsValidator(validator)) {
address recoveredAddress = IK1Validator(validator).validateSignature(signedHash, signature);

if (recoveredAddress == address(0)) {
return false;
}

if (OwnerManager._k1IsOwner(recoveredAddress)) {
return true;
}
} else if (_isModuleValidator(validator)) {
if (_isModuleValidator(validator)) {
return IModuleValidator(validator).handleValidation(signedHash, signature);
}

Expand Down
7 changes: 0 additions & 7 deletions src/interfaces/IModule.sol

This file was deleted.

56 changes: 0 additions & 56 deletions src/interfaces/IModuleManager.sol

This file was deleted.

5 changes: 4 additions & 1 deletion src/interfaces/IModuleValidator.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.24;

import { IInitable } from "../interfaces/IInitable.sol";
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

/**
* @title Modular validator interface for native AA
* @dev Add signature to module or validate existing signatures for acccount
*/
interface IModuleValidator {
interface IModuleValidator is IInitable, IERC165 {
function handleValidation(bytes32 signedHash, bytes memory signature) external view returns (bool);

function addValidationKey(bytes memory key) external returns (bool);
Expand Down
54 changes: 0 additions & 54 deletions src/interfaces/IOwnerManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,18 @@ pragma solidity ^0.8.24;
* @author https://getclave.io
*/
interface IOwnerManager {
/**
* @notice Event emitted when a r1 owner is added
* @param pubKey bytes - r1 owner that has been added
*/
event R1AddOwner(bytes pubKey);

/**
* @notice Event emitted when a k1 owner is added
* @param addr address - k1 owner that has been added
*/
event K1AddOwner(address indexed addr);

/**
* @notice Event emitted when a r1 owner is removed
* @param pubKey bytes - r1 owner that has been removed
*/
event R1RemoveOwner(bytes pubKey);

/**
* @notice Event emitted when a k1 owner is removed
* @param addr address - k1 owner that has been removed
*/
event K1RemoveOwner(address indexed addr);

/**
* @notice Event emitted when all owners are cleared
*/
event ResetOwners();

/**
* @notice Adds a r1 owner to the list of r1 owners
* @dev Can only be called by self or a whitelisted module
* @dev Public Key length must be 64 bytes
* @param pubKey bytes calldata - Public key to add to the list of r1 owners
*/
function r1AddOwner(bytes calldata pubKey) external;

/**
* @notice Adds a k1 owner to the list of k1 owners
* @dev Can only be called by self or a whitelisted module
Expand All @@ -51,49 +26,20 @@ interface IOwnerManager {
*/
function k1AddOwner(address addr) external;

/**
* @notice Removes a r1 owner from the list of r1 owners
* @dev Can only be called by self or a whitelisted module
* @dev Can not remove the last r1 owner
* @param pubKey bytes calldata - Public key to remove from the list of r1 owners
*/
function r1RemoveOwner(bytes calldata pubKey) external;

/**
* @notice Removes a k1 owner from the list of k1 owners
* @dev Can only be called by self or a whitelisted module
* @param addr address - Address to remove from the list of k1 owners
*/
function k1RemoveOwner(address addr) external;

/**
* @notice Clears both r1 owners and k1 owners and adds an r1 owner
* @dev Can only be called by self or a whitelisted module
* @dev Public Key length must be 64 bytes
* @param pubKey bytes calldata - new r1 owner to add
*/
function resetOwners(bytes calldata pubKey) external;

/**
* @notice Checks if a public key is in the list of r1 owners
* @param pubKey bytes calldata - Public key to check
* @return bool - True if the public key is in the list, false otherwise
*/
function r1IsOwner(bytes calldata pubKey) external view returns (bool);

/**
* @notice Checks if an address is in the list of k1 owners
* @param addr address - Address to check
* @return bool - True if the address is in the list, false otherwise
*/
function k1IsOwner(address addr) external view returns (bool);

/**
* @notice Returns the list of r1 owners
* @return r1OwnerList bytes[] memory - Array of r1 owner public keys
*/
function r1ListOwners() external view returns (bytes[] memory r1OwnerList);

/**
* @notice Returns the list of k1 owners
* @return k1OwnerList address[] memory - Array of k1 owner addresses
Expand Down
Loading
Loading