Skip to content

Commit

Permalink
chore: clean up unused code
Browse files Browse the repository at this point in the history
R1 validation and keys were unreachable after changing the init
interface,
K1 validation was unused since it was validated directly without a
module (simple signature instead of modular signature)
Fallback modules were entirely unused.
Modules and exec modules could have been used, but were not and weren't
supported by the factory to be installed at init.
  • Loading branch information
cpb8010 committed Nov 27, 2024
1 parent bfdc6fb commit 4bf55f2
Show file tree
Hide file tree
Showing 13 changed files with 7 additions and 446 deletions.
6 changes: 2 additions & 4 deletions src/AAFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ 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,
address[] calldata _initialK1Owners
) external returns (address accountAddress) {
require(accountMappings[_uniqueAccountId] == address(0), "Account already exists");
Expand All @@ -64,8 +62,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 and K1 owners.
ISsoAccount(accountAddress).initialize(_initialValidators, _initialK1Owners);

accountMappings[_uniqueAccountId] = accountAddress;

Expand Down
12 changes: 1 addition & 11 deletions src/SsoAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,12 @@ 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 _initialK1Owners An array of addresses with full control over the account.
function initialize(
bytes[] calldata _initialValidators,
bytes[] calldata _initialModules,
address[] calldata _initialK1Owners
) external initializer {
function initialize(bytes[] calldata _initialValidators, 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 < _initialK1Owners.length; ++i) {
_k1AddOwner(_initialK1Owners[i]);
}
Expand Down
5 changes: 2 additions & 3 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,9 +11,9 @@ 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 {
abstract contract Auth is BootloaderAuth, SelfAuth, HookAuth {
modifier onlySelfOrModule() {
if (msg.sender != address(this) && !_isModule(msg.sender)) {
if (msg.sender != address(this)) {
revert Errors.NOT_FROM_SELF_OR_MODULE();
}
_;
Expand Down
20 changes: 0 additions & 20 deletions src/auth/ModuleAuth.sol

This file was deleted.

26 changes: 1 addition & 25 deletions src/handlers/ValidationHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,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
42 changes: 0 additions & 42 deletions src/interfaces/IModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,9 @@ pragma solidity ^0.8.24;
* @author https://getclave.io
*/
interface IModuleManager {
/**
* @notice Event emitted when a module is added
* @param module address - Address of the added module
*/
event AddModule(address indexed module);

/**
* @notice Event emitted when a module is removed
* @param module address - Address of the removed module
*/
event RemoveModule(address indexed module);

/**
* @notice Add a module to the list of modules and call it's init function
* @dev Can only be called by self or a module
* @param moduleAndData bytes calldata - Address of the module and data to initialize it with
*/
function addModule(bytes calldata moduleAndData) external;

/**
* @notice Remove a module from the list of modules and call it's disable function
* @dev Can only be called by self or a module
* @param module address - Address of the module to remove
*/
function removeModule(address module) external;

/**
* @notice Allow modules to execute arbitrary calls on behalf of the account
* @dev Can only be called by a module
* @param to address - Address to call
* @param value uint256 - Eth to send with call
* @param data bytes memory - Data to make the call with
*/
function executeFromModule(address to, uint256 value, bytes memory data) external;

/**
* @notice Check if an address is in the list of modules
* @param addr address - Address to check
* @return bool - True if the address is a module, false otherwise
*/
function isModule(address addr) external returns (bool);

/**
* @notice Get the list of modules
* @return moduleList address[] memory - List of modules
*/
function listModules() external view returns (address[] memory moduleList);
}
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
8 changes: 1 addition & 7 deletions src/interfaces/ISsoAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,5 @@ interface ISsoAccount is
{
event FeePaid();

// TODO: instead of splitting the modules by types here, we can just have a single array that checks the type of the module
// and installs it 7579 style
function initialize(
bytes[] calldata initialValidators,
bytes[] calldata initialModules,
address[] calldata k1Owners
) external;
function initialize(bytes[] calldata initialValidators, address[] calldata k1Owners) external;
}
40 changes: 0 additions & 40 deletions src/interfaces/IValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ pragma solidity ^0.8.24;
* @author https://getclave.io
*/
interface IValidatorManager {
/**
* @notice Event emitted when a r1 validator is added
* @param validator address - Address of the added r1 validator
*/
event R1AddValidator(address indexed validator);

/**
* @notice Event emitted when a k1 validator is added
* @param validator address - Address of the added k1 validator
Expand All @@ -24,12 +18,6 @@ interface IValidatorManager {
*/
event AddModuleValidator(address indexed validator);

/**
* @notice Event emitted when a r1 validator is removed
* @param validator address - Address of the removed r1 validator
*/
event R1RemoveValidator(address indexed validator);

/**
* @notice Event emitted when a k1 validator is removed
* @param validator address - Address of the removed k1 validator
Expand All @@ -42,13 +30,6 @@ interface IValidatorManager {
*/
event RemoveModuleValidator(address indexed validator);

/**
* @notice Adds a validator to the list of r1 validators
* @dev Can only be called by self or a whitelisted module
* @param validator address - Address of the r1 validator to add
*/
function r1AddValidator(address validator) external;

/**
* @notice Adds a validator to the list of modular validators
* @dev Can only be called by self or a whitelisted module
Expand All @@ -64,14 +45,6 @@ interface IValidatorManager {
*/
function k1AddValidator(address validator) external;

/**
* @notice Removes a validator from the list of r1 validators
* @dev Can only be called by self or a whitelisted module
* @dev Can not remove the last validator
* @param validator address - Address of the validator to remove
*/
function r1RemoveValidator(address validator) external;

/**
* @notice Removes a validator from the list of k1 validators
* @dev Can only be called by self or a whitelisted module
Expand All @@ -86,13 +59,6 @@ interface IValidatorManager {
*/
function removeModuleValidator(address validator) external;

/**
* @notice Checks if an address is in the r1 validator list
* @param validator address -Address of the validator to check
* @return True if the address is a validator, false otherwise
*/
function r1IsValidator(address validator) external view returns (bool);

/**
* @notice Checks if an address is in the k1 validator list
* @param validator address - Address of the validator to check
Expand All @@ -107,12 +73,6 @@ interface IValidatorManager {
*/
function isModuleValidator(address validator) external view returns (bool);

/**
* @notice Returns the list of r1 validators
* @return validatorList address[] memory - Array of r1 validator addresses
*/
function r1ListValidators() external view returns (address[] memory validatorList);

/**
* @notice Returns the list of k1 validators
* @return validatorList address[] memory - Array of k1 validator addresses
Expand Down
16 changes: 0 additions & 16 deletions src/libraries/SsoStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,17 @@ library SsoStorage {
struct Layout {
// ┌───────────────────┐
// │ Ownership Data │
mapping(bytes => bytes) r1Owners;
mapping(address => address) k1Owners;
uint256[50] __gap_0;
// └───────────────────┘

// ┌───────────────────┐
// │ Fallback │
address defaultFallbackContract; // for next version
mapping(bytes4 selector => address) fallbackContractBySelector;
uint256[50] __gap_1;
// └───────────────────┘

// ┌───────────────────┐
// │ Validation │
mapping(address => address) r1Validators;
mapping(address => address) k1Validators;
mapping(address => address) moduleValidators;
uint256[50] __gap_2;
// └───────────────────┘

// ┌───────────────────┐
// │ Module │
mapping(address => address) modules;
mapping(address => address) execModules;
uint256[50] __gap_3;
// └───────────────────┘

// ┌───────────────────┐
// │ Hooks │
mapping(address => address) validationHooks;
Expand Down
Loading

0 comments on commit 4bf55f2

Please sign in to comment.