Skip to content

Commit

Permalink
feat: verify msg.sender to be the owner when calling registerPoh
Browse files Browse the repository at this point in the history
  • Loading branch information
Julink-eth committed Apr 17, 2024
1 parent ca8e95f commit 0afae19
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ error InsufficientValue();
error Unauthorised(bytes32 node);
error MaxCommitmentAgeTooLow();
error MaxCommitmentAgeTooHigh();
error PohVerificationFailed(address owner);
error OwnerAlreadyRegistered(address owner);
error SenderNotOwner(address owner, address sender);

/**
* @dev A registrar controller for registering and renewing names at fixed cost.
Expand Down Expand Up @@ -177,15 +180,20 @@ contract ETHRegistrarController is
uint16 ownerControlledFuses,
bytes memory signature
) public {
// Check if the address has already registered using registerPoh
require(
!hasRegisteredPoh[owner],
"Address has already registered using PoH"
);
require(
pohVerifier.verify(signature, owner),
"POH verification failed"
);
// The sender of the transaction needs to be the owner
if (msg.sender != owner) {
revert SenderNotOwner(owner, msg.sender);
}

// An andress can own only one domain using its PoH
if (hasRegisteredPoh[owner]) {
revert OwnerAlreadyRegistered(owner);
}

// Check that the signature sent is valid, this is the reference for an address to have a valid PoH
if (!pohVerifier.verify(signature, owner)) {
revert PohVerificationFailed(owner);
}

// Mark this address as having successfully registered
hasRegisteredPoh[owner] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ contract('ETHRegistrarController', function () {
const name = 'pohname'
const duration = 28 * 24 * 60 * 60 // 28 days in seconds
const secret = ethers.utils.formatBytes32String('secret')
const human = signers[1].address
const human = signers[0].address
const signature = ethers.utils.hexlify(ethers.utils.randomBytes(65)) // Mock signature

// Generate a commitment for the registration
Expand Down

0 comments on commit 0afae19

Please sign in to comment.