Skip to content

Commit

Permalink
adding transferownership to resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroknots committed Feb 14, 2024
1 parent 4502efb commit 462376e
Show file tree
Hide file tree
Showing 29 changed files with 187 additions and 608 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ evm_version = 'paris'

[fmt]
bracket_spacing = true
line_length = 100
line_length = 140
multiline_func_header = "all"
number_underscore="thousands"

Expand Down
8 changes: 1 addition & 7 deletions src/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
112 changes: 41 additions & 71 deletions src/IRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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 */
Expand Down Expand Up @@ -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);

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
Expand Down
13 changes: 2 additions & 11 deletions src/core/Attestation.sol
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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);
}

Expand Down
48 changes: 8 additions & 40 deletions src/core/AttestationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 });

Expand All @@ -69,25 +62,15 @@ 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
ResolverUID resolverUID;
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
Expand Down Expand Up @@ -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 });
}

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
Expand All @@ -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] });
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
}
}
Loading

0 comments on commit 462376e

Please sign in to comment.