Skip to content

Commit

Permalink
fix: FunctionRegistry bugs + tests (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstam authored Oct 31, 2023
1 parent 5e5a54c commit 7703e85
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 15 deletions.
4 changes: 1 addition & 3 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
/broadcast

# Docs
docs/
Expand Down
11 changes: 7 additions & 4 deletions contracts/src/FunctionRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.16;

import {IFunctionRegistry} from "./interfaces/IFunctionRegistry.sol";

contract FunctionRegistry is IFunctionRegistry {
abstract contract FunctionRegistry is IFunctionRegistry {
/// @dev Maps function identifiers to their corresponding verifiers.
mapping(bytes32 => address) public verifiers;

Expand All @@ -18,7 +18,7 @@ contract FunctionRegistry is IFunctionRegistry {
external
returns (bytes32 functionId)
{
functionId = getFunctionId(msg.sender, _name);
functionId = getFunctionId(_owner, _name);
if (address(verifiers[functionId]) != address(0)) {
revert FunctionAlreadyRegistered(functionId); // should call update instead
}
Expand All @@ -39,7 +39,7 @@ contract FunctionRegistry is IFunctionRegistry {
external
returns (bytes32 functionId, address verifier)
{
functionId = getFunctionId(msg.sender, _name);
functionId = getFunctionId(_owner, _name);
if (address(verifiers[functionId]) != address(0)) {
revert FunctionAlreadyRegistered(functionId); // should call update instead
}
Expand All @@ -66,6 +66,9 @@ contract FunctionRegistry is IFunctionRegistry {
if (_verifier == address(0)) {
revert VerifierCannotBeZero();
}
if (_verifier == verifiers[functionId]) {
revert VerifierAlreadyUpdated(functionId);
}
verifiers[functionId] = _verifier;

emit FunctionVerifierUpdated(functionId, _verifier);
Expand All @@ -90,7 +93,7 @@ contract FunctionRegistry is IFunctionRegistry {
}

/// @notice Returns the functionId for a given owner and function name.
/// @param _owner The owner of the function (sender of registerFunction).
/// @param _owner The owner of the function.
/// @param _name The name of the function.
function getFunctionId(address _owner, string memory _name)
public
Expand Down
1 change: 1 addition & 0 deletions contracts/src/interfaces/IFunctionRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface IFunctionRegistryErrors {
error EmptyBytecode();
error FailedDeploy();
error VerifierCannotBeZero();
error VerifierAlreadyUpdated(bytes32 functionId);
error FunctionAlreadyRegistered(bytes32 functionId);
error NotFunctionOwner(address owner, address actualOwner);
}
Expand Down
Loading

0 comments on commit 7703e85

Please sign in to comment.