diff --git a/foundry.toml b/foundry.toml index 1a276d6e..e554080e 100644 --- a/foundry.toml +++ b/foundry.toml @@ -7,7 +7,7 @@ evm_version = 'paris' [fmt] bracket_spacing = true -line_length = 100 +line_length = 140 multiline_func_header = "all" number_underscore="thousands" diff --git a/src/DataTypes.sol b/src/DataTypes.sol index 9e425dd6..d5e95e07 100644 --- a/src/DataTypes.sol +++ b/src/DataTypes.sol @@ -103,13 +103,7 @@ type AttestationDataRef is address; using { attestationDataRefEq as == } for AttestationDataRef global; -function attestationDataRefEq( - AttestationDataRef uid1, - AttestationDataRef uid2 -) - pure - returns (bool) -{ +function attestationDataRefEq(AttestationDataRef uid1, AttestationDataRef uid2) pure returns (bool) { return AttestationDataRef.unwrap(uid1) == AttestationDataRef.unwrap(uid2); } diff --git a/src/IRegistry.sol b/src/IRegistry.sol index 7df601ca..81645cf8 100644 --- a/src/IRegistry.sol +++ b/src/IRegistry.sol @@ -27,13 +27,7 @@ interface IERC7484 { function check(address module, ModuleType moduleType) external view; - function checkForAccount( - address smartAccount, - address module, - ModuleType moduleType - ) - external - view; + function checkForAccount(address smartAccount, address module, ModuleType moduleType) external view; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* Check with external attester(s) */ @@ -82,22 +76,14 @@ interface IRegistry is IERC7484 { * Get trusted attester for a specific smartAccount * @param smartAccount The address of the smartAccount */ - function findTrustedAttesters(address smartAccount) - external - view - returns (address[] memory attesters); + function findTrustedAttesters(address smartAccount) external view returns (address[] memory attesters); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* Attestations */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ event Revoked(address indexed moduleAddr, address indexed revoker, SchemaUID schema); - event Attested( - address indexed moduleAddr, - address indexed attester, - SchemaUID schemaUID, - AttestationDataRef indexed sstore2Pointer - ); + event Attested(address indexed moduleAddr, address indexed attester, SchemaUID schemaUID, AttestationDataRef indexed sstore2Pointer); error AlreadyRevoked(); error ModuleNotFoundInRegistry(address module); @@ -147,13 +133,7 @@ interface IRegistry is IERC7484 { * @param request An AttestationRequest * @param signature The signature of the attester. ECDSA or ERC1271 */ - function attest( - SchemaUID schemaUID, - address attester, - AttestationRequest calldata request, - bytes calldata signature - ) - external; + function attest(SchemaUID schemaUID, address attester, AttestationRequest calldata request, bytes calldata signature) external; /** * Allows attester to attest by signing an AttestationRequest (ECDSA or ERC1271) @@ -168,24 +148,12 @@ interface IRegistry is IERC7484 { * @param requests An array of AttestationRequest * @param signature The signature of the attester. ECDSA or ERC1271 */ - function attest( - SchemaUID schemaUID, - address attester, - AttestationRequest[] calldata requests, - bytes calldata signature - ) - external; + function attest(SchemaUID schemaUID, address attester, AttestationRequest[] calldata requests, bytes calldata signature) external; /** * Getter function to get AttestationRequest made by one attester */ - function findAttestation( - address module, - address attester - ) - external - view - returns (AttestationRecord memory attestation); + function findAttestation(address module, address attester) external view returns (AttestationRecord memory attestation); /** * Getter function to get AttestationRequest made by multiple attesters @@ -229,12 +197,7 @@ interface IRegistry is IERC7484 { * @param request the RevocationRequest * @param signature ECDSA or ERC1271 signature */ - function revoke( - address attester, - RevocationRequest calldata request, - bytes calldata signature - ) - external; + function revoke(address attester, RevocationRequest calldata request, bytes calldata signature) external; /** * Allows attester to revoke an attestation by signing an RevocationRequest (ECDSA or ERC1271) @@ -244,20 +207,13 @@ interface IRegistry is IERC7484 { * @param requests array of RevocationRequests * @param signature ECDSA or ERC1271 signature */ - function revoke( - address attester, - RevocationRequest[] calldata requests, - bytes calldata signature - ) - external; + function revoke(address attester, RevocationRequest[] calldata requests, bytes calldata signature) external; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* Module Registration */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // Event triggered when a module is deployed. - event ModuleRegistration( - address indexed implementation, address indexed sender, ResolverUID resolverUID - ); + event ModuleRegistration(address indexed implementation, address indexed sender, ResolverUID resolverUID); error AlreadyRegistered(address module); error InvalidDeployment(); @@ -285,6 +241,9 @@ interface IRegistry is IERC7484 { /** * Registry can use other factories to deploy the module + * @notice This function is used to deploy and register a module using a factory contract. + * Since one of the parameters of this function is a unique resolverUID and any + * registered module address can only be registered once, using this function is of risk for a frontrun attack */ function deployViaFactory( address factory, @@ -298,18 +257,16 @@ interface IRegistry is IERC7484 { /** * Already deployed module addresses can be registered on the registry + * @notice This function is used to deploy and register an already deployed module. + * Since one of the parameters of this function is a unique resolverUID and any + * registered module address can only be registered once, using this function is of risk for a frontrun attack * @param resolverUID The resolverUID to be used for the module * @param moduleAddress The address of the module to be registered * @param metadata The metadata to be stored on the registry. * This field is optional, and might be used by the module developer to store additional * information about the module or facilitate business logic with the Resolver stub */ - function registerModule( - ResolverUID resolverUID, - address moduleAddress, - bytes calldata metadata - ) - external; + function registerModule(ResolverUID resolverUID, address moduleAddress, bytes calldata metadata) external; /** * in conjunction with the deployModule() function, this function let's you @@ -318,22 +275,13 @@ interface IRegistry is IERC7484 { * @param initCode module initcode * @return moduleAddress counterfactual address of the module deployment */ - function calcModuleAddress( - bytes32 salt, - bytes calldata initCode - ) - external - view - returns (address); + function calcModuleAddress(bytes32 salt, bytes calldata initCode) external view returns (address); /** * Getter function to get the stored ModuleRecord for a specific module address. * @param moduleAddress The address of the module */ - function findModule(address moduleAddress) - external - view - returns (ModuleRecord memory moduleRecord); + function findModule(address moduleAddress) external view returns (ModuleRecord memory moduleRecord); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* Manage Schemas */ @@ -374,13 +322,35 @@ interface IRegistry is IERC7484 { /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ event NewResolver(ResolverUID indexed uid, address indexed resolver); + event NewResolverOwner(ResolverUID indexed uid, address newOwner); error ResolverAlreadyExists(); - function registerResolver(IExternalResolver _resolver) external returns (ResolverUID uid); + /** + * Allows Marketplace Agents to register external resolvers. + * @param resolver external resolver contract + * @return uid ResolverUID of the registered resolver + */ + function registerResolver(IExternalResolver resolver) external returns (ResolverUID uid); + /** + * Entities that previously regsitered an external resolver, may update the implementation address. + * @param uid The UID of the resolver. + * @param resolver The new resolver implementation address. + */ function setResolver(ResolverUID uid, IExternalResolver resolver) external; + /** + * Transfer ownership of resolverUID to a new address + * @param uid The UID of the resolver to transfer ownership for + * @param newOwner The address of the new owner + */ + function transferResolverOwnership(ResolverUID uid, address newOwner) external; + + /** + * Getter function to get the ResolverRecord of a registerd resolver + * @param uid The UID of the resolver. + */ function findResolver(ResolverUID uid) external view returns (ResolverRecord memory record); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ diff --git a/src/core/Attestation.sol b/src/core/Attestation.sol index 53a7a99b..0d7ffea0 100644 --- a/src/core/Attestation.sol +++ b/src/core/Attestation.sol @@ -1,9 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.24; -import { - AttestationRecord, AttestationRequest, RevocationRequest, SchemaUID -} from "../DataTypes.sol"; +import { AttestationRecord, AttestationRequest, RevocationRequest, SchemaUID } from "../DataTypes.sol"; import { AttestationManager } from "./AttestationManager.sol"; import { IRegistry } from "../IRegistry.sol"; @@ -39,14 +37,7 @@ abstract contract Attestation is IRegistry, AttestationManager { /** * @inheritdoc IRegistry */ - function findAttestation( - address module, - address attester - ) - external - view - returns (AttestationRecord memory attestation) - { + function findAttestation(address module, address attester) external view returns (AttestationRecord memory attestation) { attestation = _getAttestation(module, attester); } diff --git a/src/core/AttestationManager.sol b/src/core/AttestationManager.sol index 14c50e42..9e55ff3f 100644 --- a/src/core/AttestationManager.sol +++ b/src/core/AttestationManager.sol @@ -32,8 +32,7 @@ abstract contract AttestationManager is IRegistry, ModuleManager, SchemaManager, using AttestationLib for address; using ModuleTypeLib for ModuleType[]; - mapping(address module => mapping(address attester => AttestationRecord attestation)) internal - $moduleToAttesterToAttestations; + mapping(address module => mapping(address attester => AttestationRecord attestation)) internal $moduleToAttesterToAttestations; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* Attestation */ @@ -47,13 +46,7 @@ abstract contract AttestationManager is IRegistry, ModuleManager, SchemaManager, * function will get the external IExternalResolver for the module - that the attestation is for * and call it, if an external Resolver was set */ - function _attest( - address attester, - SchemaUID schemaUID, - AttestationRequest calldata request - ) - internal - { + function _attest(address attester, SchemaUID schemaUID, AttestationRequest calldata request) internal { (AttestationRecord memory record, ResolverUID resolverUID) = _storeAttestation({ schemaUID: schemaUID, attester: attester, request: request }); @@ -69,13 +62,7 @@ abstract contract AttestationManager is IRegistry, ModuleManager, SchemaManager, * function will get the external IExternalResolver for the module - that the attestation is for * and call it, if an external Resolver was set */ - function _attest( - address attester, - SchemaUID schemaUID, - AttestationRequest[] calldata requests - ) - internal - { + function _attest(address attester, SchemaUID schemaUID, AttestationRequest[] calldata requests) internal { uint256 length = requests.length; AttestationRecord[] memory records = new AttestationRecord[](length); // loop will check that the batched attestation is made ONLY for the same resolver @@ -83,11 +70,7 @@ abstract contract AttestationManager is IRegistry, ModuleManager, SchemaManager, for (uint256 i; i < length; i++) { ResolverUID resolverUID_cache; // save the attestation record into records array. - (records[i], resolverUID_cache) = _storeAttestation({ - schemaUID: schemaUID, - attester: attester, - request: requests[i] - }); + (records[i], resolverUID_cache) = _storeAttestation({ schemaUID: schemaUID, attester: attester, request: requests[i] }); // cache the first resolverUID and compare it to the rest // If the resolverUID is different, revert // @dev if you want to use different resolvers, make different attestation calls @@ -160,12 +143,7 @@ abstract contract AttestationManager is IRegistry, ModuleManager, SchemaManager, // SSTORE attestation to registry storage $moduleToAttesterToAttestations[request.moduleAddr][attester] = record; - emit Attested({ - moduleAddr: module, - attester: attester, - schemaUID: schemaUID, - sstore2Pointer: sstore2Pointer - }); + emit Attested({ moduleAddr: module, attester: attester, schemaUID: schemaUID, sstore2Pointer: sstore2Pointer }); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ @@ -178,8 +156,7 @@ abstract contract AttestationManager is IRegistry, ModuleManager, SchemaManager, * and pass the RevocationRecord to the resolver to check if the revocation is valid */ function _revoke(address attester, RevocationRequest calldata request) internal { - (AttestationRecord memory record, ResolverUID resolverUID) = - _storeRevocation(attester, request); + (AttestationRecord memory record, ResolverUID resolverUID) = _storeRevocation(attester, request); record.tryExternalResolverOnRevocation({ $resolver: $resolvers[resolverUID] }); } @@ -220,8 +197,7 @@ abstract contract AttestationManager is IRegistry, ModuleManager, SchemaManager, internal returns (AttestationRecord memory record, ResolverUID resolverUID) { - AttestationRecord storage $attestation = - $moduleToAttesterToAttestations[request.moduleAddr][revoker]; + AttestationRecord storage $attestation = $moduleToAttesterToAttestations[request.moduleAddr][revoker]; // SLOAD entire record. This will later be passed to the resolver record = $attestation; @@ -252,15 +228,7 @@ abstract contract AttestationManager is IRegistry, ModuleManager, SchemaManager, * Returns the attestation records for the given module and attesters. * This function is expected to be used by TrustManager and TrustManagerExternalAttesterList */ - function _getAttestation( - address module, - address attester - ) - internal - view - override - returns (AttestationRecord storage $attestation) - { + function _getAttestation(address module, address attester) internal view override returns (AttestationRecord storage $attestation) { $attestation = $moduleToAttesterToAttestations[module][attester]; } } diff --git a/src/core/ModuleManager.sol b/src/core/ModuleManager.sol index 78bd6927..6e77682a 100644 --- a/src/core/ModuleManager.sol +++ b/src/core/ModuleManager.sol @@ -61,36 +61,20 @@ abstract contract ModuleManager is IRegistry, ResolverManager { metadata: metadata }); - record.requireExternalResolverOnModuleRegistration({ - moduleAddress: moduleAddress, - $resolver: $resolver - }); + record.requireExternalResolverOnModuleRegistration({ moduleAddress: moduleAddress, $resolver: $resolver }); } /** * @inheritdoc IRegistry */ - function calcModuleAddress( - bytes32 salt, - bytes calldata initCode - ) - external - view - returns (address) - { + function calcModuleAddress(bytes32 salt, bytes calldata initCode) external view returns (address) { return initCode.calcAddress(salt); } /** * @inheritdoc IRegistry */ - function registerModule( - ResolverUID resolverUID, - address moduleAddress, - bytes calldata metadata - ) - external - { + function registerModule(ResolverUID resolverUID, address moduleAddress, bytes calldata metadata) external { ResolverRecord storage $resolver = $resolvers[resolverUID]; // ensure that non-zero resolverUID was provided @@ -104,10 +88,7 @@ abstract contract ModuleManager is IRegistry, ResolverManager { }); // resolve module registration - record.requireExternalResolverOnModuleRegistration({ - moduleAddress: moduleAddress, - $resolver: $resolver - }); + record.requireExternalResolverOnModuleRegistration({ moduleAddress: moduleAddress, $resolver: $resolver }); } /** @@ -144,10 +125,7 @@ abstract contract ModuleManager is IRegistry, ResolverManager { metadata: metadata }); - record.requireExternalResolverOnModuleRegistration({ - moduleAddress: moduleAddress, - $resolver: $resolver - }); + record.requireExternalResolverOnModuleRegistration({ moduleAddress: moduleAddress, $resolver: $resolver }); } function _storeModuleRecord( @@ -170,28 +148,20 @@ abstract contract ModuleManager is IRegistry, ResolverManager { if (!_isContract(moduleAddress)) revert InvalidDeployment(); // Store module metadata in _modules mapping - moduleRegistration = - ModuleRecord({ resolverUID: resolverUID, sender: sender, metadata: metadata }); + moduleRegistration = ModuleRecord({ resolverUID: resolverUID, sender: sender, metadata: metadata }); // Store module record in _modules mapping $moduleAddrToRecords[moduleAddress] = moduleRegistration; // Emit ModuleRegistration event - emit ModuleRegistration({ - implementation: moduleAddress, - sender: sender, - resolverUID: resolverUID - }); + // TODO: add flag to event to indicate if module was deployed or registered + emit ModuleRegistration({ implementation: moduleAddress, sender: sender, resolverUID: resolverUID }); } /** * @inheritdoc IRegistry */ - function findModule(address moduleAddress) - external - view - returns (ModuleRecord memory moduleRecord) - { + function findModule(address moduleAddress) external view returns (ModuleRecord memory moduleRecord) { return $moduleAddrToRecords[moduleAddress]; } } diff --git a/src/core/ResolverManager.sol b/src/core/ResolverManager.sol index e4a76393..f4e4f065 100644 --- a/src/core/ResolverManager.sol +++ b/src/core/ResolverManager.sol @@ -28,10 +28,7 @@ abstract contract ResolverManager is IRegistry { * If a resolver is not address(0), we check if it supports the IExternalResolver interface */ modifier onlyResolver(IExternalResolver resolver) { - if ( - address(resolver) == address(0) - || !resolver.supportsInterface(type(IExternalResolver).interfaceId) - ) { + if (address(resolver) == address(0) || !resolver.supportsInterface(type(IExternalResolver).interfaceId)) { revert InvalidResolver(resolver); } _; @@ -40,14 +37,9 @@ abstract contract ResolverManager is IRegistry { /** * @inheritdoc IRegistry */ - function registerResolver(IExternalResolver resolver) - external - onlyResolver(resolver) - returns (ResolverUID uid) - { + function registerResolver(IExternalResolver resolver) external onlyResolver(resolver) returns (ResolverUID uid) { // build a ResolverRecord from the input - ResolverRecord memory resolverRecord = - ResolverRecord({ resolver: resolver, resolverOwner: msg.sender }); + ResolverRecord memory resolverRecord = ResolverRecord({ resolver: resolver, resolverOwner: msg.sender }); // Computing a unique ID for the schema using its properties uid = resolverRecord.getUID(); @@ -79,6 +71,14 @@ abstract contract ResolverManager is IRegistry { emit NewResolver(uid, address(resolver)); } + /** + * @inheritdoc IRegistry + */ + function transferResolverOwnership(ResolverUID uid, address newOwner) external onlyResolverOwner(uid) { + $resolvers[uid].resolverOwner = newOwner; + emit NewResolverOwner(uid, newOwner); + } + /** * @inheritdoc IRegistry */ diff --git a/src/core/SchemaManager.sol b/src/core/SchemaManager.sol index 7efee3e2..6bafe409 100644 --- a/src/core/SchemaManager.sol +++ b/src/core/SchemaManager.sol @@ -34,8 +34,7 @@ abstract contract SchemaManager is IRegistry { onlySchemaValidator(validator) returns (SchemaUID uid) { - SchemaRecord memory schemaRecord = - SchemaRecord({ validator: validator, registeredAt: _time(), schema: schema }); + SchemaRecord memory schemaRecord = SchemaRecord({ validator: validator, registeredAt: _time(), schema: schema }); // Computing a unique ID for the schema using its properties uid = schemaRecord.getUID(); @@ -54,10 +53,7 @@ abstract contract SchemaManager is IRegistry { * If a validator is not address(0), we check if it supports the IExternalSchemaValidator interface */ modifier onlySchemaValidator(IExternalSchemaValidator validator) { - if ( - address(validator) != address(0) - && !validator.supportsInterface(type(IExternalSchemaValidator).interfaceId) - ) { + if (address(validator) != address(0) && !validator.supportsInterface(type(IExternalSchemaValidator).interfaceId)) { revert InvalidSchemaValidator(validator); } _; diff --git a/src/core/SignedAttestation.sol b/src/core/SignedAttestation.sol index 25e39daf..27b3f7cb 100644 --- a/src/core/SignedAttestation.sol +++ b/src/core/SignedAttestation.sol @@ -19,14 +19,7 @@ contract SignedAttestation is IRegistry, Attestation, EIP712 { /** * @inheritdoc IRegistry */ - function attest( - SchemaUID schemaUID, - address attester, - AttestationRequest calldata request, - bytes calldata signature - ) - external - { + function attest(SchemaUID schemaUID, address attester, AttestationRequest calldata request, bytes calldata signature) external { uint256 nonce = ++attesterNonce[attester]; bytes32 digest = _hashTypedData(request.hash(nonce)); bool valid = SignatureCheckerLib.isValidSignatureNow(attester, digest, signature); @@ -38,14 +31,7 @@ contract SignedAttestation is IRegistry, Attestation, EIP712 { /** * @inheritdoc IRegistry */ - function attest( - SchemaUID schemaUID, - address attester, - AttestationRequest[] calldata requests, - bytes calldata signature - ) - external - { + function attest(SchemaUID schemaUID, address attester, AttestationRequest[] calldata requests, bytes calldata signature) external { uint256 nonce = ++attesterNonce[attester]; bytes32 digest = _hashTypedData(requests.hash(nonce)); bool valid = SignatureCheckerLib.isValidSignatureNow(attester, digest, signature); @@ -57,13 +43,7 @@ contract SignedAttestation is IRegistry, Attestation, EIP712 { /** * @inheritdoc IRegistry */ - function revoke( - address attester, - RevocationRequest calldata request, - bytes calldata signature - ) - external - { + function revoke(address attester, RevocationRequest calldata request, bytes calldata signature) external { uint256 nonce = ++attesterNonce[attester]; bytes32 digest = _hashTypedData(request.hash(nonce)); bool valid = SignatureCheckerLib.isValidSignatureNow(attester, digest, signature); @@ -75,13 +55,7 @@ contract SignedAttestation is IRegistry, Attestation, EIP712 { /** * @inheritdoc IRegistry */ - function revoke( - address attester, - RevocationRequest[] calldata requests, - bytes calldata signature - ) - external - { + function revoke(address attester, RevocationRequest[] calldata requests, bytes calldata signature) external { uint256 nonce = ++attesterNonce[attester]; bytes32 digest = _hashTypedData(requests.hash(nonce)); bool valid = SignatureCheckerLib.isValidSignatureNow(attester, digest, signature); @@ -97,58 +71,24 @@ contract SignedAttestation is IRegistry, Attestation, EIP712 { /** * override thats used by Solady's EIP712 cache (constructor) */ - function _domainNameAndVersion() - internal - view - virtual - override - returns (string memory name, string memory version) - { + function _domainNameAndVersion() internal view virtual override returns (string memory name, string memory version) { name = "RhinestoneRegistry"; version = "v1.0"; } - function getDigest( - AttestationRequest calldata request, - address attester - ) - external - view - returns (bytes32 digest) - { + function getDigest(AttestationRequest calldata request, address attester) external view returns (bytes32 digest) { digest = _hashTypedData(request.hash(attesterNonce[attester] + 1)); } - function getDigest( - AttestationRequest[] calldata requests, - address attester - ) - external - view - returns (bytes32 digest) - { + function getDigest(AttestationRequest[] calldata requests, address attester) external view returns (bytes32 digest) { digest = _hashTypedData(requests.hash(attesterNonce[attester] + 1)); } - function getDigest( - RevocationRequest calldata request, - address attester - ) - external - view - returns (bytes32 digest) - { + function getDigest(RevocationRequest calldata request, address attester) external view returns (bytes32 digest) { digest = _hashTypedData(request.hash(attesterNonce[attester] + 1)); } - function getDigest( - RevocationRequest[] calldata requests, - address attester - ) - external - view - returns (bytes32 digest) - { + function getDigest(RevocationRequest[] calldata requests, address attester) external view returns (bytes32 digest) { digest = _hashTypedData(requests.hash(attesterNonce[attester] + 1)); } } diff --git a/src/core/TrustManager.sol b/src/core/TrustManager.sol index 3e56a41f..0d18c342 100644 --- a/src/core/TrustManager.sol +++ b/src/core/TrustManager.sol @@ -1,12 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.24; -import { - AttestationRecord, - PackedModuleTypes, - ModuleType, - TrustedAttesterRecord -} from "../DataTypes.sol"; +import { AttestationRecord, PackedModuleTypes, ModuleType, TrustedAttesterRecord } from "../DataTypes.sol"; import { ZERO_TIMESTAMP, ZERO_MODULE_TYPE, ZERO_ADDRESS } from "../Common.sol"; // solhint-disable-next-line no-unused-import import { IRegistry, IERC7484 } from "../IRegistry.sol"; @@ -85,14 +80,7 @@ abstract contract TrustManager is IRegistry, TrustManagerExternalAttesterList { /** * @inheritdoc IERC7484 */ - function checkForAccount( - address smartAccount, - address module, - ModuleType moduleType - ) - external - view - { + function checkForAccount(address smartAccount, address module, ModuleType moduleType) external view { _check(smartAccount, module, moduleType); } @@ -117,15 +105,13 @@ abstract contract TrustManager is IRegistry, TrustManagerExternalAttesterList { // smart account only has ONE trusted attester // use this condition to save gas else if (threshold == 1) { - AttestationRecord storage $attestation = - _getAttestation({ module: module, attester: attester }); + AttestationRecord storage $attestation = _getAttestation({ module: module, attester: attester }); _requireValidAttestation(moduleType, $attestation); } // smart account has more than one trusted attester else { // loop though list and check if the attestation is valid - AttestationRecord storage $attestation = - _getAttestation({ module: module, attester: attester }); + AttestationRecord storage $attestation = _getAttestation({ module: module, attester: attester }); _requireValidAttestation(moduleType, $attestation); for (uint256 i = 1; i < attesterCount; i++) { threshold--; @@ -145,13 +131,7 @@ abstract contract TrustManager is IRegistry, TrustManagerExternalAttesterList { * - not expired * - correct module type (if not ZERO_MODULE_TYPE) */ - function _requireValidAttestation( - ModuleType expectedType, - AttestationRecord storage $attestation - ) - internal - view - { + function _requireValidAttestation(ModuleType expectedType, AttestationRecord storage $attestation) internal view { uint256 attestedAt; uint256 expirationTime; uint256 revocationTime; @@ -203,11 +183,7 @@ abstract contract TrustManager is IRegistry, TrustManagerExternalAttesterList { /** * @inheritdoc IRegistry */ - function findTrustedAttesters(address smartAccount) - public - view - returns (address[] memory attesters) - { + function findTrustedAttesters(address smartAccount) public view returns (address[] memory attesters) { TrustedAttesterRecord storage $trustedAttesters = $accountToAttester[smartAccount]; uint256 count = $trustedAttesters.attesterCount; address attester0 = $trustedAttesters.attester; diff --git a/src/core/TrustManagerExternalAttesterList.sol b/src/core/TrustManagerExternalAttesterList.sol index 0b1598c4..4fcbeb85 100644 --- a/src/core/TrustManagerExternalAttesterList.sol +++ b/src/core/TrustManagerExternalAttesterList.sol @@ -155,12 +155,5 @@ abstract contract TrustManagerExternalAttesterList is IRegistry { revert InsufficientAttestations(); } - function _getAttestation( - address module, - address attester - ) - internal - view - virtual - returns (AttestationRecord storage $attestation); + function _getAttestation(address module, address attester) internal view virtual returns (AttestationRecord storage $attestation); } diff --git a/src/external/IExternalResolver.sol b/src/external/IExternalResolver.sol index 0f5beb33..a2dea004 100644 --- a/src/external/IExternalResolver.sol +++ b/src/external/IExternalResolver.sol @@ -18,15 +18,9 @@ interface IExternalResolver is IERC165 { * * @return Whether the attestation is valid. */ - function resolveAttestation(AttestationRecord calldata attestation) - external - payable - returns (bool); + function resolveAttestation(AttestationRecord calldata attestation) external payable returns (bool); - function resolveAttestation(AttestationRecord[] calldata attestation) - external - payable - returns (bool); + function resolveAttestation(AttestationRecord[] calldata attestation) external payable returns (bool); /** * @dev Processes an attestation revocation and verifies if it can be revoked. @@ -35,14 +29,8 @@ interface IExternalResolver is IERC165 { * * @return Whether the attestation can be revoked. */ - function resolveRevocation(AttestationRecord calldata attestation) - external - payable - returns (bool); - function resolveRevocation(AttestationRecord[] calldata attestation) - external - payable - returns (bool); + function resolveRevocation(AttestationRecord calldata attestation) external payable returns (bool); + function resolveRevocation(AttestationRecord[] calldata attestation) external payable returns (bool); /** * @dev Processes a Module Registration diff --git a/src/external/IExternalSchemaValidator.sol b/src/external/IExternalSchemaValidator.sol index e43ba503..96c722c8 100644 --- a/src/external/IExternalSchemaValidator.sol +++ b/src/external/IExternalSchemaValidator.sol @@ -11,13 +11,10 @@ interface IExternalSchemaValidator is IERC165 { /** * @notice Validates an attestation request. */ - function validateSchema(AttestationRecord calldata attestation) external view returns (bool); + function validateSchema(AttestationRecord calldata attestation) external returns (bool); /** * @notice Validates an array of attestation requests. */ - function validateSchema(AttestationRecord[] calldata attestations) - external - view - returns (bool); + function validateSchema(AttestationRecord[] calldata attestations) external returns (bool); } diff --git a/src/external/examples/ERC7512Schema.sol b/src/external/examples/ERC7512Schema.sol index 4cf76a1d..9d0619f9 100644 --- a/src/external/examples/ERC7512Schema.sol +++ b/src/external/examples/ERC7512Schema.sol @@ -50,12 +50,7 @@ contract ERC7512SchemaValidator is IExternalSchemaValidator, ERC7512 { return (interfaceID == type(IExternalSchemaValidator).interfaceId); } - function validateSchema(AttestationRecord calldata attestation) - public - view - override - returns (bool valid) - { + function validateSchema(AttestationRecord calldata attestation) public view override returns (bool valid) { AuditSummary memory summary = abi.decode(attestation.dataPointer.sload2(), (AuditSummary)); if (summary.auditedContract.deployment != attestation.moduleAddr) { return false; @@ -64,17 +59,10 @@ contract ERC7512SchemaValidator is IExternalSchemaValidator, ERC7512 { return false; } - valid = SignatureCheckerLib.isValidSignatureNow( - summary.auditorSignature.signer, summary.auditHash, summary.auditorSignature.data - ); + valid = SignatureCheckerLib.isValidSignatureNow(summary.auditorSignature.signer, summary.auditHash, summary.auditorSignature.data); } - function validateSchema(AttestationRecord[] calldata attestations) - external - view - override - returns (bool valid) - { + function validateSchema(AttestationRecord[] calldata attestations) external view override returns (bool valid) { uint256 length = attestations.length; for (uint256 i = 0; i < length; i++) { if (!validateSchema(attestations[i])) { diff --git a/src/external/examples/TokenizedResolver.sol b/src/external/examples/TokenizedResolver.sol index 79c45c07..73b1eff1 100644 --- a/src/external/examples/TokenizedResolver.sol +++ b/src/external/examples/TokenizedResolver.sol @@ -14,37 +14,13 @@ contract TokenizedResolver is ResolverBase { function supportsInterface(bytes4 interfaceID) external view override returns (bool) { } - function resolveAttestation(AttestationRecord calldata attestation) - external - payable - override - onlyRegistry - returns (bool) - { } + function resolveAttestation(AttestationRecord calldata attestation) external payable override onlyRegistry returns (bool) { } - function resolveAttestation(AttestationRecord[] calldata attestation) - external - payable - override - onlyRegistry - returns (bool) - { } + function resolveAttestation(AttestationRecord[] calldata attestation) external payable override onlyRegistry returns (bool) { } - function resolveRevocation(AttestationRecord calldata attestation) - external - payable - override - onlyRegistry - returns (bool) - { } + function resolveRevocation(AttestationRecord calldata attestation) external payable override onlyRegistry returns (bool) { } - function resolveRevocation(AttestationRecord[] calldata attestation) - external - payable - override - onlyRegistry - returns (bool) - { } + function resolveRevocation(AttestationRecord[] calldata attestation) external payable override onlyRegistry returns (bool) { } function resolveModuleRegistration( address sender, diff --git a/src/lib/AttestationLib.sol b/src/lib/AttestationLib.sol index 88d51378..fec4db1a 100644 --- a/src/lib/AttestationLib.sol +++ b/src/lib/AttestationLib.sol @@ -6,8 +6,7 @@ import { SSTORE2 } from "solady/utils/SSTORE2.sol"; library AttestationLib { // The hash of the data type used to relay calls to the attest function. It's the value of - bytes32 internal constant ATTEST_TYPEHASH = - keccak256("AttestationRequest(address,uint48,bytes,uint256[])"); + bytes32 internal constant ATTEST_TYPEHASH = keccak256("AttestationRequest(address,uint48,bytes,uint256[])"); // The hash of the data type used to relay calls to the revoke function. It's the value of bytes32 internal constant REVOKE_TYPEHASH = keccak256("RevocationRequest(address)"); @@ -16,13 +15,7 @@ library AttestationLib { data = SSTORE2.read(AttestationDataRef.unwrap(dataPointer)); } - function sstore2( - AttestationRequest calldata request, - bytes32 salt - ) - internal - returns (AttestationDataRef dataPointer) - { + function sstore2(AttestationRequest calldata request, bytes32 salt) internal returns (AttestationDataRef dataPointer) { /** * @dev We are using CREATE2 to deterministically generate the address of the attestation data. * Checking if an attestation pointer already exists, would cost more GAS in the average case. @@ -34,47 +27,19 @@ library AttestationLib { salt = keccak256(abi.encodePacked(attester, module, block.timestamp, block.chainid)); } - function hash( - AttestationRequest calldata data, - uint256 nonce - ) - internal - pure - returns (bytes32 _hash) - { + function hash(AttestationRequest calldata data, uint256 nonce) internal pure returns (bytes32 _hash) { _hash = keccak256(abi.encode(ATTEST_TYPEHASH, keccak256(abi.encode(data)), nonce)); } - function hash( - AttestationRequest[] calldata data, - uint256 nonce - ) - internal - pure - returns (bytes32 _hash) - { + function hash(AttestationRequest[] calldata data, uint256 nonce) internal pure returns (bytes32 _hash) { _hash = keccak256(abi.encode(ATTEST_TYPEHASH, keccak256(abi.encode(data)), nonce)); } - function hash( - RevocationRequest calldata data, - uint256 nonce - ) - internal - pure - returns (bytes32 _hash) - { + function hash(RevocationRequest calldata data, uint256 nonce) internal pure returns (bytes32 _hash) { _hash = keccak256(abi.encode(REVOKE_TYPEHASH, keccak256(abi.encode(data)), nonce)); } - function hash( - RevocationRequest[] calldata data, - uint256 nonce - ) - internal - pure - returns (bytes32 _hash) - { + function hash(RevocationRequest[] calldata data, uint256 nonce) internal pure returns (bytes32 _hash) { _hash = keccak256(abi.encode(REVOKE_TYPEHASH, keccak256(abi.encode(data)), nonce)); } } diff --git a/src/lib/Helpers.sol b/src/lib/Helpers.sol index 2ea60941..86d8d156 100644 --- a/src/lib/Helpers.sol +++ b/src/lib/Helpers.sol @@ -12,11 +12,7 @@ library UIDLib { * @return schema UID. */ function getUID(SchemaRecord memory schemaRecord) internal view returns (SchemaUID) { - return SchemaUID.wrap( - keccak256( - abi.encodePacked(msg.sender, schemaRecord.schema, address(schemaRecord.validator)) - ) - ); + return SchemaUID.wrap(keccak256(abi.encodePacked(msg.sender, schemaRecord.schema, address(schemaRecord.validator)))); } /** diff --git a/src/lib/ModuleDeploymentLib.sol b/src/lib/ModuleDeploymentLib.sol index c56a74e1..5cb9eb79 100644 --- a/src/lib/ModuleDeploymentLib.sol +++ b/src/lib/ModuleDeploymentLib.sol @@ -11,20 +11,11 @@ library ModuleDeploymentLib { modifier containsCaller(bytes32 salt) { // prevent contract submissions from being stolen from tx.pool by requiring // that the first 20 bytes of the submitted salt match msg.sender. - require( - (address(bytes20(salt)) == msg.sender) || (bytes20(salt) == bytes20(0)), "Invalid salt" - ); + require((address(bytes20(salt)) == msg.sender) || (bytes20(salt) == bytes20(0)), "Invalid salt"); _; } - function deploy( - bytes calldata _initCode, - bytes32 salt - ) - internal - containsCaller(salt) - returns (address deploymentAddress) - { + function deploy(bytes calldata _initCode, bytes32 salt) internal containsCaller(salt) returns (address deploymentAddress) { // move the initialization code from calldata to memory. bytes memory initCode = _initCode; @@ -60,14 +51,7 @@ library ModuleDeploymentLib { * @return targetDeploymentAddress The address that the contract would be deployed * at if the CREATE2 opcode was called with the specified _code and _salt. */ - function calcAddress( - bytes calldata initCode, - bytes32 salt - ) - internal - view - returns (address targetDeploymentAddress) - { + function calcAddress(bytes calldata initCode, bytes32 salt) internal view returns (address targetDeploymentAddress) { targetDeploymentAddress = address( uint160( // downcast to match the address type. uint256( // convert to uint to truncate upper digits. diff --git a/src/lib/StubLib.sol b/src/lib/StubLib.sol index 0d8cd1c5..a79a6db7 100644 --- a/src/lib/StubLib.sol +++ b/src/lib/StubLib.sol @@ -17,52 +17,29 @@ library StubLib { /** * @notice if Schema Validator is set, it will call validateSchema() on the validator */ - function requireExternalSchemaValidation( - AttestationRecord memory attestationRecord, - SchemaRecord storage $schema - ) - internal - view - { + function requireExternalSchemaValidation(AttestationRecord memory attestationRecord, SchemaRecord storage $schema) internal { // only run this function if the selected schemaUID exists if ($schema.registeredAt == ZERO_TIMESTAMP) revert IRegistry.InvalidSchema(); // validate Schema IExternalSchemaValidator validator = $schema.validator; // if validator is set, call the validator - if ( - address(validator) != ZERO_ADDRESS - && validator.validateSchema(attestationRecord) == false - ) { + if (address(validator) != ZERO_ADDRESS && validator.validateSchema(attestationRecord) == false) { revert IRegistry.ExternalError_SchemaValidation(); } } - function requireExternalSchemaValidation( - AttestationRecord[] memory attestationRecords, - SchemaRecord storage $schema - ) - internal - view - { + function requireExternalSchemaValidation(AttestationRecord[] memory attestationRecords, SchemaRecord storage $schema) internal { // only run this function if the selected schemaUID exists if ($schema.registeredAt == ZERO_TIMESTAMP) revert IRegistry.InvalidSchema(); // validate Schema IExternalSchemaValidator validator = $schema.validator; // if validator is set, call the validator - if ( - address(validator) != ZERO_ADDRESS - && validator.validateSchema(attestationRecords) == false - ) { + if (address(validator) != ZERO_ADDRESS && validator.validateSchema(attestationRecords) == false) { revert IRegistry.ExternalError_SchemaValidation(); } } - function requireExternalResolverOnAttestation( - AttestationRecord memory attestationRecord, - ResolverRecord storage $resolver - ) - internal - { + function requireExternalResolverOnAttestation(AttestationRecord memory attestationRecord, ResolverRecord storage $resolver) internal { IExternalResolver resolverContract = $resolver.resolver; if (address(resolverContract) == ZERO_ADDRESS) return; @@ -133,13 +110,8 @@ library StubLib { if (address(resolverContract) != ZERO_ADDRESS) return; - if ( - resolverContract.resolveModuleRegistration({ - sender: msg.sender, - moduleAddress: moduleAddress, - record: moduleRecord - }) == false - ) { + if (resolverContract.resolveModuleRegistration({ sender: msg.sender, moduleAddress: moduleAddress, record: moduleRecord }) == false) + { revert IRegistry.ExternalError_ModuleRegistration(); } } diff --git a/test/Attestation.t.sol b/test/Attestation.t.sol index 62807e35..2d06a87a 100644 --- a/test/Attestation.t.sol +++ b/test/Attestation.t.sol @@ -23,19 +23,10 @@ contract AttestationTest is BaseTest { for (uint256 i; i < types.length; i++) { typesEnc[i] = ModuleType.wrap(types[i]); } - request = AttestationRequest({ - moduleAddr: module, - expirationTime: expirationTime, - data: data, - moduleTypes: typesEnc - }); + request = AttestationRequest({ moduleAddr: module, expirationTime: expirationTime, data: data, moduleTypes: typesEnc }); } - function mockRevocation(address module) - internal - pure - returns (RevocationRequest memory request) - { + function mockRevocation(address module) internal pure returns (RevocationRequest memory request) { request = RevocationRequest({ moduleAddr: module }); } @@ -43,8 +34,7 @@ contract AttestationTest is BaseTest { address module = address(new MockModule()); registry.registerModule(defaultResolverUID, module, ""); uint32[] memory types = new uint32[](1); - AttestationRequest memory request = - mockAttestation(module, uint48(block.timestamp + 1), "", types); + AttestationRequest memory request = mockAttestation(module, uint48(block.timestamp + 1), "", types); // It should store. registry.attest(defaultSchemaUID, request); AttestationRecord memory record = registry.findAttestation(module, attester1.addr); @@ -59,8 +49,7 @@ contract AttestationTest is BaseTest { address module = address(new MockModule()); registry.registerModule(defaultResolverUID, module, ""); uint32[] memory types = new uint32[](1); - AttestationRequest memory request = - mockAttestation(module, uint48(block.timestamp + 1), "", types); + AttestationRequest memory request = mockAttestation(module, uint48(block.timestamp + 1), "", types); // It should store. registry.attest(defaultSchemaUID, request); AttestationRecord memory record = registry.findAttestation(module, attester1.addr); @@ -91,13 +80,7 @@ contract AttestationTest is BaseTest { assertEq(record.attester, attester1.addr); } - function test_WhenAttestingWithExpirationTimeInThePast( - address module, - bytes memory data, - uint32 moduleType - ) - external - { + function test_WhenAttestingWithExpirationTimeInThePast(address module, bytes memory data, uint32 moduleType) external { vm.assume(moduleType > 31); uint48 expirationTime = uint48(block.timestamp - 1000); @@ -151,10 +134,7 @@ contract AttestationTest is BaseTest { registry.attest(defaultSchemaUID, request); } - function test_WhenRevokingAttestationThatDoesntExist(address module) - external - prankWithAccount(attester1) - { + function test_WhenRevokingAttestationThatDoesntExist(address module) external prankWithAccount(attester1) { // It should revert. vm.expectRevert(abi.encodeWithSelector(IRegistry.AttestationNotFound.selector)); registry.revoke(mockRevocation(module)); @@ -165,8 +145,7 @@ contract AttestationTest is BaseTest { // It should call ExternalResolver. uint32[] memory types = new uint32[](1); - AttestationRequest memory request = - mockAttestation(address(module1), uint48(block.timestamp + 1), "", types); + AttestationRequest memory request = mockAttestation(address(module1), uint48(block.timestamp + 1), "", types); // It should store. registry.attest(defaultSchemaUID, request); @@ -199,8 +178,7 @@ contract AttestationTest is BaseTest { uint32[] memory types = new uint32[](2); types[0] = 1; types[1] = 2; - AttestationRequest memory request = - mockAttestation(address(module1), uint48(block.timestamp + 100), "", types); + AttestationRequest memory request = mockAttestation(address(module1), uint48(block.timestamp + 100), "", types); bytes32 digest = registry.getDigest(request, attester1.addr); bytes memory sig = ecdsaSign(attester1.key, digest); @@ -262,8 +240,7 @@ contract AttestationTest is BaseTest { function test_WhenUsingInvalidECDSA() external whenAttestingWithSignature { uint32[] memory types = new uint32[](1); - AttestationRequest memory request = - mockAttestation(address(module1), uint48(block.timestamp + 100), "", types); + AttestationRequest memory request = mockAttestation(address(module1), uint48(block.timestamp + 100), "", types); bytes32 digest = registry.getDigest(request, attester1.addr); bytes memory sig = ecdsaSign(attester1.key, digest); @@ -289,14 +266,12 @@ contract AttestationTest is BaseTest { function test_WhenUsingValidERC1271() external whenAttestingWithSignature { uint32[] memory types = new uint32[](1); - AttestationRequest memory request = - mockAttestation(address(module1), uint48(block.timestamp + 100), "", types); + AttestationRequest memory request = mockAttestation(address(module1), uint48(block.timestamp + 100), "", types); bytes memory sig = "signature"; registry.attest(defaultSchemaUID, address(erc1271AttesterTrue), request, sig); - AttestationRecord memory record = - registry.findAttestation(address(module1), address(erc1271AttesterTrue)); + AttestationRecord memory record = registry.findAttestation(address(module1), address(erc1271AttesterTrue)); assertEq(record.time, block.timestamp); assertEq(record.expirationTime, request.expirationTime); @@ -313,8 +288,7 @@ contract AttestationTest is BaseTest { bytes memory sig = "signature"; registry.attest(defaultSchemaUID, address(erc1271AttesterTrue), requests, sig); - AttestationRecord memory record = - registry.findAttestation(address(module1), address(erc1271AttesterTrue)); + AttestationRecord memory record = registry.findAttestation(address(module1), address(erc1271AttesterTrue)); assertEq(record.time, block.timestamp); assertEq(record.expirationTime, requests[0].expirationTime); @@ -338,22 +312,14 @@ contract AttestationTest is BaseTest { function test_WhenUsingInvalidERC1271() external whenAttestingWithSignature { // It should revert. uint32[] memory types = new uint32[](1); - AttestationRequest memory request = - mockAttestation(address(module1), uint48(block.timestamp + 100), "", types); + AttestationRequest memory request = mockAttestation(address(module1), uint48(block.timestamp + 100), "", types); bytes memory sig = "signature"; vm.expectRevert(abi.encodeWithSelector(IRegistry.InvalidSignature.selector)); registry.attest(defaultSchemaUID, address(erc1271AttesterFalse), request, sig); } - function ecdsaSign( - uint256 privKey, - bytes32 digest - ) - internal - pure - returns (bytes memory signature) - { + function ecdsaSign(uint256 privKey, bytes32 digest) internal pure returns (bytes memory signature) { (uint8 v, bytes32 r, bytes32 s) = vm.sign(privKey, digest); return abi.encodePacked(r, s, v); } diff --git a/test/Base.t.sol b/test/Base.t.sol index adcd66a8..bbbae36c 100644 --- a/test/Base.t.sol +++ b/test/Base.t.sol @@ -85,9 +85,7 @@ contract BaseTest is Test { vm.prank(opsEntity1.addr); defaultResolverUID = registry.registerResolver(IExternalResolver(address(resolverTrue))); vm.prank(opsEntity1.addr); - defaultSchemaUID = registry.registerSchema( - defaultSchema, IExternalSchemaValidator(address(schemaValidatorTrue)) - ); + defaultSchemaUID = registry.registerSchema(defaultSchema, IExternalSchemaValidator(address(schemaValidatorTrue))); vm.prank(moduleDev1.addr); registry.registerModule(defaultResolverUID, address(module1), ""); diff --git a/test/ModuleRegistration.t.sol b/test/ModuleRegistration.t.sol index be6a5ed1..ecfad1b7 100644 --- a/test/ModuleRegistration.t.sol +++ b/test/ModuleRegistration.t.sol @@ -39,10 +39,7 @@ contract ModuleRegistrationTest is BaseTest { assertTrue(moduleAddr == moduleAddrCalc); } - function test_WhenRegisteringAModuleOnAnInvalidResolverUID() - external - prankWithAccount(moduleDev1) - { + function test_WhenRegisteringAModuleOnAnInvalidResolverUID() external prankWithAccount(moduleDev1) { MockModule newModule = new MockModule(); // It should revert. ResolverUID invalidUID = ResolverUID.wrap(hex"00"); @@ -54,20 +51,14 @@ contract ModuleRegistrationTest is BaseTest { registry.registerModule(invalidUID, address(newModule), ""); } - function test_WhenRegisteringAModuleOnAValidResolverUID() - external - prankWithAccount(moduleDev1) - { + function test_WhenRegisteringAModuleOnAValidResolverUID() external prankWithAccount(moduleDev1) { // It should register. MockModule newModule = new MockModule(); registry.registerModule(defaultResolverUID, address(newModule), ""); } - function test_WhenRegisteringAModuleOnAInValidResolverUID() - external - prankWithAccount(moduleDev1) - { + function test_WhenRegisteringAModuleOnAInValidResolverUID() external prankWithAccount(moduleDev1) { // It should revert MockModule newModule = new MockModule(); @@ -75,17 +66,12 @@ contract ModuleRegistrationTest is BaseTest { registry.registerModule(ResolverUID.wrap(bytes32("foobar")), address(newModule), ""); } - function test_WhenRegisteringTwoModulesWithTheSameBytecode() - external - prankWithAccount(moduleDev1) - { + function test_WhenRegisteringTwoModulesWithTheSameBytecode() external prankWithAccount(moduleDev1) { MockModule newModule = new MockModule(); // It should revert. registry.registerModule(defaultResolverUID, address(newModule), ""); - vm.expectRevert( - abi.encodeWithSelector(IRegistry.AlreadyRegistered.selector, address(newModule)) - ); + vm.expectRevert(abi.encodeWithSelector(IRegistry.AlreadyRegistered.selector, address(newModule))); registry.registerModule(defaultResolverUID, address(newModule), ""); } @@ -96,22 +82,16 @@ contract ModuleRegistrationTest is BaseTest { factory.setReturnAddress(address(0)); vm.expectRevert(); - registry.deployViaFactory( - address(factory), abi.encodeCall(factory.deployFn, ()), "", defaultResolverUID - ); + registry.deployViaFactory(address(factory), abi.encodeCall(factory.deployFn, ()), "", defaultResolverUID); factory.setReturnAddress(address(1)); vm.expectRevert(); - registry.deployViaFactory( - address(factory), abi.encodeCall(factory.deployFn, ()), "", defaultResolverUID - ); + registry.deployViaFactory(address(factory), abi.encodeCall(factory.deployFn, ()), "", defaultResolverUID); MockModule newModule = new MockModule(); factory.setReturnAddress(address(newModule)); - registry.deployViaFactory( - address(factory), abi.encodeCall(factory.deployFn, ()), "", defaultResolverUID - ); + registry.deployViaFactory(address(factory), abi.encodeCall(factory.deployFn, ()), "", defaultResolverUID); } function test_WhenUsingInvalidFactory() public { diff --git a/test/Resolver.t.sol b/test/Resolver.t.sol index c69f0df1..d1c5fe36 100644 --- a/test/Resolver.t.sol +++ b/test/Resolver.t.sol @@ -50,4 +50,32 @@ contract ResolverTest is BaseTest { // ResolverRecord memory record = registry.resolvers(resolverUID); // assertEq(address(record.resolver), address(newResolver2)); } + + function test_WhenUpdatingOwnership_Authorized() external whenUpdatingResolver { + MockResolver newResolver = new MockResolver(false); + vm.prank(opsEntity1.addr); + ResolverUID resolverUID = registry.registerResolver(IExternalResolver(address(newResolver))); + ResolverRecord memory record = registry.findResolver(resolverUID); + assertEq(record.resolverOwner, opsEntity1.addr); + + vm.prank(opsEntity1.addr); + registry.transferResolverOwnership(resolverUID, opsEntity2.addr); + + record = registry.findResolver(resolverUID); + assertEq(record.resolverOwner, opsEntity2.addr); + } + + function test_WhenUpdatingOwnership_NotAuthorized() external whenUpdatingResolver { + MockResolver newResolver = new MockResolver(false); + vm.prank(opsEntity1.addr); + ResolverUID resolverUID = registry.registerResolver(IExternalResolver(address(newResolver))); + ResolverRecord memory record = registry.findResolver(resolverUID); + assertEq(record.resolverOwner, opsEntity1.addr); + + vm.prank(opsEntity2.addr); + vm.expectRevert(); + registry.transferResolverOwnership(resolverUID, opsEntity2.addr); + + + } } diff --git a/test/SchemaValidation.t.sol b/test/SchemaValidation.t.sol index 63b649d9..39a829b7 100644 --- a/test/SchemaValidation.t.sol +++ b/test/SchemaValidation.t.sol @@ -11,8 +11,7 @@ contract SchemaValidationTest is BaseTest { function test_WhenSchemaAlreadyRegistered() external whenRegisteringNewSchema { string memory schema = "schema"; SchemaUID uid = registry.registerSchema(schema, IExternalSchemaValidator(address(0))); - SchemaUID uid1 = - registry.registerSchema(schema, IExternalSchemaValidator(address(schemaValidatorFalse))); + SchemaUID uid1 = registry.registerSchema(schema, IExternalSchemaValidator(address(schemaValidatorFalse))); assertTrue(uid != uid1); } diff --git a/test/TrustDelegation.t.sol b/test/TrustDelegation.t.sol index 1df8297e..6db7c1ca 100644 --- a/test/TrustDelegation.t.sol +++ b/test/TrustDelegation.t.sol @@ -17,11 +17,7 @@ contract TrustTest is AttestationTest { _; } - function test_WhenSupplyingOneAttester() - external - whenSettingAttester - prankWithAccount(smartAccount1) - { + function test_WhenSupplyingOneAttester() external whenSettingAttester prankWithAccount(smartAccount1) { // It should set. address[] memory trustedAttesters = new address[](1); trustedAttesters[0] = address(attester1.addr); @@ -31,11 +27,7 @@ contract TrustTest is AttestationTest { assertEq(result[0], address(attester1.addr)); } - function test_WhenSupplyingManyAttesters(address[] memory attesters) - external - whenSettingAttester - prankWithAccount(smartAccount1) - { + function test_WhenSupplyingManyAttesters(address[] memory attesters) external whenSettingAttester prankWithAccount(smartAccount1) { vm.assume(attesters.length < 100); vm.assume(attesters.length > 0); for (uint256 i; i < attesters.length; i++) { diff --git a/test/invariance/Handler.t.sol b/test/invariance/Handler.t.sol index 01040345..985d8977 100644 --- a/test/invariance/Handler.t.sol +++ b/test/invariance/Handler.t.sol @@ -58,19 +58,11 @@ contract Handler is CommonBase, StdCheats, StdUtils { function handle_registerSchema(string memory schema) public returns (SchemaUID uid) { MockSchemaValidator schemaValidatorTrue = new MockSchemaValidator(true); - uid = - REGISTRY.registerSchema(schema, IExternalSchemaValidator(address(schemaValidatorTrue))); + uid = REGISTRY.registerSchema(schema, IExternalSchemaValidator(address(schemaValidatorTrue))); SchemaRecord memory record = REGISTRY.findSchema(uid); } - function handle_registerModule( - uint256 randomResolverNr, - address moduleAddr, - bytes calldata bytecode, - bytes calldata metadata - ) - public - { + function handle_registerModule(uint256 randomResolverNr, address moduleAddr, bytes calldata bytecode, bytes calldata metadata) public { vm.etch(moduleAddr, bytecode); ResolverUID uid = _pickRandomResolverUID(randomResolverNr); @@ -122,17 +114,9 @@ contract Handler is CommonBase, StdCheats, StdUtils { REGISTRY.attest(uid, requests); } - function handle_registerModuleWithFactory( - uint256 randomResolverNr, - bytes calldata bytecode, - uint256 value - ) - external - { + function handle_registerModuleWithFactory(uint256 randomResolverNr, bytes calldata bytecode, uint256 value) external { vm.deal(address(this), value); ResolverUID uid = _pickRandomResolverUID(randomResolverNr); - REGISTRY.deployViaFactory{ value: value }( - address(FACTORY), abi.encodeCall(MockFactory.deploy, (bytecode)), "", uid - ); + REGISTRY.deployViaFactory{ value: value }(address(FACTORY), abi.encodeCall(MockFactory.deploy, (bytecode)), "", uid); } } diff --git a/test/invariance/invariant_ImmutableData.t.sol b/test/invariance/invariant_ImmutableData.t.sol index 98ae32ec..345c0216 100644 --- a/test/invariance/invariant_ImmutableData.t.sol +++ b/test/invariance/invariant_ImmutableData.t.sol @@ -10,8 +10,7 @@ contract ImmutableData is BaseTest { super.setUp(); handler = new Handler(registry); - AttestationRecord memory attRecord = - registry.findAttestation(address(module1), invarAttester.addr); + AttestationRecord memory attRecord = registry.findAttestation(address(module1), invarAttester.addr); defaultDataRef = attRecord.dataPointer; bytes4[] memory targetSelectors = new bytes4[](6); @@ -36,8 +35,7 @@ contract ImmutableData is BaseTest { } function invariant_attestation_immutable() public { - AttestationRecord memory record = - registry.findAttestation(address(module1), invarAttester.addr); + AttestationRecord memory record = registry.findAttestation(address(module1), invarAttester.addr); assertTrue(record.dataPointer == defaultDataRef); assertEq(record.moduleAddr, address(module1)); assertEq(record.attester, invarAttester.addr); diff --git a/test/mocks/MockResolver.sol b/test/mocks/MockResolver.sol index b6943c3a..27b8f326 100644 --- a/test/mocks/MockResolver.sol +++ b/test/mocks/MockResolver.sol @@ -24,43 +24,23 @@ contract MockResolver is IExternalResolver { if (interfaceId == type(IExternalResolver).interfaceId) return true; } - function resolveAttestation(AttestationRecord calldata attestation) - external - payable - override - returns (bool) - { + function resolveAttestation(AttestationRecord calldata attestation) external payable override returns (bool) { onAttestCalled = true; return returnVal; } - function resolveAttestation(AttestationRecord[] calldata attestation) - external - payable - override - returns (bool) - { + function resolveAttestation(AttestationRecord[] calldata attestation) external payable override returns (bool) { onAttestCalled = true; return returnVal; } - function resolveRevocation(AttestationRecord calldata attestation) - external - payable - override - returns (bool) - { + function resolveRevocation(AttestationRecord calldata attestation) external payable override returns (bool) { revert(); onRevokeCalled = true; return returnVal; } - function resolveRevocation(AttestationRecord[] calldata attestation) - external - payable - override - returns (bool) - { + function resolveRevocation(AttestationRecord[] calldata attestation) external payable override returns (bool) { revert(); onRevokeCalled = true; return returnVal; diff --git a/test/mocks/MockSchemaValidator.sol b/test/mocks/MockSchemaValidator.sol index 2e0c9b7c..7c98940d 100644 --- a/test/mocks/MockSchemaValidator.sol +++ b/test/mocks/MockSchemaValidator.sol @@ -14,21 +14,11 @@ contract MockSchemaValidator is IExternalSchemaValidator { if (interfaceId == type(IExternalSchemaValidator).interfaceId) return true; } - function validateSchema(AttestationRecord calldata attestation) - external - view - override - returns (bool) - { + function validateSchema(AttestationRecord calldata attestation) external view override returns (bool) { return returnVal; } - function validateSchema(AttestationRecord[] calldata attestations) - external - view - override - returns (bool) - { + function validateSchema(AttestationRecord[] calldata attestations) external view override returns (bool) { return returnVal; } }