Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: adding default resolverUID #56

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct SchemaRecord {
}

struct ResolverRecord {
IExternalResolver resolver; // Optional resolver.
IExternalResolver resolver; // resolver.
address resolverOwner; // The address of the account used to register the resolver.
}

Expand Down
7 changes: 2 additions & 5 deletions src/Registry.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.24;

import { SignedAttestation } from "./core/SignedAttestation.sol";
import { IRegistry } from "./IRegistry.sol";
import { SignedAttestation } from "./core/SignedAttestation.sol";
/**
* @author zeroknots
*/

contract Registry is IRegistry, SignedAttestation {
// TODO: should we create a default resolverUID thats address(0).
// this will allow the registry to be usable right after deployment without any resolver
}
contract Registry is IRegistry, SignedAttestation { }
8 changes: 3 additions & 5 deletions src/core/ModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ abstract contract ModuleManager is IRegistry, ResolverManager {
returns (address moduleAddress)
{
ResolverRecord storage $resolver = $resolvers[resolverUID];
// ensure that existing resolverUID was provided
if ($resolver.resolverOwner == ZERO_ADDRESS) revert InvalidResolver($resolver.resolver);

moduleAddress = initCode.deploy(salt);
Expand All @@ -72,8 +73,7 @@ abstract contract ModuleManager is IRegistry, ResolverManager {
*/
function registerModule(ResolverUID resolverUID, address moduleAddress, bytes calldata metadata) external {
ResolverRecord storage $resolver = $resolvers[resolverUID];

// ensure that non-zero resolverUID was provided
// ensure that existing resolverUID was provided
if ($resolver.resolverOwner == ZERO_ADDRESS) revert InvalidResolver($resolver.resolver);

ModuleRecord memory record = _storeModuleRecord({
Expand Down Expand Up @@ -101,7 +101,7 @@ abstract contract ModuleManager is IRegistry, ResolverManager {
returns (address moduleAddress)
{
ResolverRecord storage $resolver = $resolvers[resolverUID];
if ($resolver.resolverOwner == ZERO_ADDRESS) revert InvalidResolverUID(resolverUID);
if ($resolver.resolverOwner == ZERO_ADDRESS) revert InvalidResolver($resolver.resolver);
// prevent someone from calling a registry function pretending its a factory
if (factory == address(this)) revert FactoryCallFailed(factory);
// call external factory to deploy module
Expand Down Expand Up @@ -131,8 +131,6 @@ abstract contract ModuleManager is IRegistry, ResolverManager {
internal
returns (ModuleRecord memory moduleRegistration)
{
// ensure that non-zero resolverUID was provided
if (resolverUID == EMPTY_RESOLVER_UID) revert InvalidDeployment();
// ensure moduleAddress is not already registered
if ($moduleAddrToRecords[moduleAddress].resolverUID != EMPTY_RESOLVER_UID) {
revert AlreadyRegistered(moduleAddress);
Expand Down
5 changes: 5 additions & 0 deletions src/core/ResolverManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ abstract contract ResolverManager is IRegistry {

mapping(ResolverUID uid => ResolverRecord resolver) internal $resolvers;

constructor() {
ResolverRecord storage $resolver = $resolvers[ResolverUID.wrap(bytes32(0))];
$resolver.resolverOwner = address(this);
}

/**
* @dev Modifier to require that the caller is the owner of a resolver
*
Expand Down
4 changes: 1 addition & 3 deletions src/lib/ModuleDeploymentLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ pragma solidity ^0.8.24;
* @title ModuleDeploymentLib
* @dev A library that can be used to deploy the Registry
* @author zeroknots
* source: https://github.com/0age/metamorphic/blob/master/contracts/ImmutableCreate2Factory.sol#L194-L203
*/
library ModuleDeploymentLib {
error InvalidSalt();
error InvalidAddress();
// source: https://github.com/0age/metamorphic/blob/master/contracts/ImmutableCreate2Factory.sol#L194-L203

modifier containsCaller(bytes32 salt) {
// prevent contract submissions from being stolen from tx.pool by requiring
Expand Down Expand Up @@ -71,6 +71,4 @@ library ModuleDeploymentLib {
)
);
}

error InvalidDeployment();
}
2 changes: 1 addition & 1 deletion src/lib/StubLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ library StubLib {
{
IExternalResolver resolverContract = $resolver.resolver;

if (address(resolverContract) != ZERO_ADDRESS) return;
if (address(resolverContract) == ZERO_ADDRESS) return;

if (resolverContract.resolveModuleRegistration({ sender: msg.sender, moduleAddress: moduleAddress, record: moduleRecord }) == false)
{
Expand Down
13 changes: 12 additions & 1 deletion test/ModuleRegistration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract ModuleRegistrationTest is BaseTest {
function test_WhenRegisteringAModuleOnAnInvalidResolverUID() external prankWithAccount(moduleDev1) {
MockModule newModule = new MockModule();
// It should revert.
ResolverUID invalidUID = ResolverUID.wrap(hex"00");
ResolverUID invalidUID = ResolverUID.wrap(hex"01");
vm.expectRevert(abi.encodeWithSelector(IRegistry.InvalidResolver.selector, address(0)));
registry.registerModule(invalidUID, address(newModule), "");

Expand Down Expand Up @@ -103,4 +103,15 @@ contract ModuleRegistrationTest is BaseTest {
vm.expectRevert();
registry.deployViaFactory(address(registry), "", "", defaultResolverUID);
}

function test_WhenUsingDefaultResolverUID() public prankWithAccount(moduleDev1) {
bytes32 salt = bytes32(abi.encodePacked(address(moduleDev1.addr), bytes12(0)));

bytes memory bytecode = type(MockModule).creationCode;

ResolverUID nullUID = ResolverUID.wrap(bytes32(0));
address moduleAddr = registry.deployModule(salt, nullUID, bytecode, "");
ModuleRecord memory record = registry.findModule(moduleAddr);
assertTrue(record.resolverUID == nullUID);
}
}
Loading