Skip to content

Commit

Permalink
Feature/v0.3 fixes (#55)
Browse files Browse the repository at this point in the history
* moduleTypes now checked to not be duplicates on attestation
  • Loading branch information
zeroknots authored Feb 12, 2024
1 parent 0b60962 commit 0382e33
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 218 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/foundryTest.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
on:
push:
branches:
- main
- 'releases/**'

name: Foundry Tests

on: [push]
jobs:
check:
name: Foundry project
Expand Down
47 changes: 45 additions & 2 deletions src/IRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
ModuleRecord,
ResolverUID,
RevocationRequest,
SchemaUID
SchemaUID,
SchemaRecord
} from "./DataTypes.sol";

import { IExternalSchemaValidator } from "./external/IExternalSchemaValidator.sol";
Expand Down Expand Up @@ -200,17 +201,48 @@ interface IRegistry is IERC7484 {
/* Revocations */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

/**
* Allows msg.sender to revoke an attstation made by the same msg.sender
*
* @dev this function will revert if the attestation is not found
* @dev this function will revert if the attestation is already revoked
*
* @param request the RevocationRequest
*/
function revoke(RevocationRequest calldata request) external;

/**
* Allows msg.sender to revoke multiple attstations made by the same msg.sender
*
* @dev this function will revert if the attestation is not found
* @dev this function will revert if the attestation is already revoked
*
* @param requests the RevocationRequests
*/
function revoke(RevocationRequest[] calldata requests) external;

/**
* Allows attester to revoke an attestation by signing an RevocationRequest (ECDSA or ERC1271)
*
* @param attester the signer / revoker
* @param request the RevocationRequest
* @param signature ECDSA or ERC1271 signature
*/
function revoke(
address attester,
RevocationRequest calldata request,
bytes calldata signature
)
external;

/**
* Allows attester to revoke an attestation by signing an RevocationRequest (ECDSA or ERC1271)
* @dev if you want to revoke multiple attestations, but from different attesters, call this function multiple times
*
* @param attester the signer / revoker
* @param requests array of RevocationRequests
* @param signature ECDSA or ERC1271 signature
*/
function revoke(
address attester,
RevocationRequest[] calldata requests,
Expand All @@ -235,6 +267,15 @@ interface IRegistry is IERC7484 {
error ModuleAddressIsNotContract(address moduleAddress);
error FactoryCallFailed(address factory);

/**
* This registry implements a CREATE2 factory, that allows module developers to register and deploy module bytecode
* @param salt The salt to be used in the CREATE2 factory
* @param resolverUID The resolverUID to be used in the CREATE2 factory
* @param initCode The initCode to be used in the CREATE2 factory
* @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 deployModule(
bytes32 salt,
ResolverUID resolverUID,
Expand All @@ -260,7 +301,7 @@ interface IRegistry is IERC7484 {
view
returns (address);

function getRegisteredModules(address moduleAddress)
function getRegisteredModule(address moduleAddress)
external
view
returns (ModuleRecord memory moduleRecord);
Expand All @@ -283,6 +324,8 @@ interface IRegistry is IERC7484 {
external
returns (SchemaUID uid);

function findSchema(SchemaUID uid) external returns (SchemaRecord memory record);

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* Manage Resolvers */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
Expand Down
9 changes: 7 additions & 2 deletions src/core/AttestationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ abstract contract AttestationManager is IRegistry, ModuleManager, SchemaManager,
// SSTORE attestation to registry storage
_moduleToAttesterToAttestations[request.moduleAddr][attester] = record;

emit Attested(module, attester, schemaUID, sstore2Pointer);
emit Attested({
moduleAddr: module,
attester: attester,
schemaUID: schemaUID,
sstore2Pointer: sstore2Pointer
});
}

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
Expand Down Expand Up @@ -243,7 +248,7 @@ abstract contract AttestationManager is IRegistry, ModuleManager, SchemaManager,
// SSTORE revocation time to registry storage
attestationStorage.revocationTime = _time();
// set revocation time to NOW
emit Revoked({ moduleAddr: record.moduleAddr, revoker: revoker, schema: record.schemaUID });
emit Revoked({ moduleAddr: request.moduleAddr, revoker: revoker, schema: record.schemaUID });
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/ModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ abstract contract ModuleManager is IRegistry, ResolverManager {
emit ModuleRegistration(moduleAddress, sender, ResolverUID.unwrap(resolverUID));
}

function getRegisteredModules(address moduleAddress)
function getRegisteredModule(address moduleAddress)
external
view
returns (ModuleRecord memory moduleRecord)
Expand Down
4 changes: 4 additions & 0 deletions src/core/SchemaManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ abstract contract SchemaManager is IRegistry {
}
_;
}

function findSchema(SchemaUID uid) external view override returns (SchemaRecord memory) {
return schemas[uid];
}
}
52 changes: 0 additions & 52 deletions src/external/examples/DebugResolver.sol.bak

This file was deleted.

32 changes: 0 additions & 32 deletions src/external/examples/SimpleValidator.sol.bak

This file was deleted.

60 changes: 0 additions & 60 deletions src/external/examples/TokenizedResolver.sol.bak

This file was deleted.

54 changes: 0 additions & 54 deletions src/external/examples/ValueResolver.sol.bak

This file was deleted.

23 changes: 16 additions & 7 deletions src/lib/ModuleTypeLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@
pragma solidity ^0.8.21;

import { PackedModuleTypes, ModuleType } from "../DataTypes.sol";
import { LibSort } from "solady/utils/LibSort.sol";
import { IRegistry } from "../IRegistry.sol";

library ModuleTypeLib {
function isType(PackedModuleTypes self, ModuleType moduleType) internal pure returns (bool) {
return (PackedModuleTypes.unwrap(self) & 2 ** ModuleType.unwrap(moduleType)) != 0;
}

function pack(ModuleType[] calldata moduleTypes) internal pure returns (PackedModuleTypes) {
uint32 result;
for (uint256 i; i < moduleTypes.length; i++) {
uint32 _type = ModuleType.unwrap(moduleTypes[i]);
if (_type > 31) revert IRegistry.InvalidModuleType();
result = result + uint32(2 ** _type);

function isType(uint32 packed, uint32 check) internal pure returns (bool) {
return (packed & 2 ** check) != 0;
}

function pack(ModuleType[] memory moduleTypes) internal pure returns (PackedModuleTypes) {
uint256 length = moduleTypes.length;
uint32 packed;
uint32 _type;
for (uint256 i; i < length; i++) {
_type = ModuleType.unwrap(moduleTypes[i]);
if (_type > 31 && isType(packed, _type)) revert IRegistry.InvalidModuleType();
packed = packed + uint32(2 ** _type);

}
return PackedModuleTypes.wrap(result);
return PackedModuleTypes.wrap(packed);
}
}
Loading

0 comments on commit 0382e33

Please sign in to comment.