Skip to content

Commit

Permalink
Merge pull request #106 from Consensys/feat/CZK-726-verify-sender
Browse files Browse the repository at this point in the history
feat: verify msg.sender to be the owner when calling registerPoh
  • Loading branch information
Julink-eth authored Apr 19, 2024
2 parents e9c6f13 + c2c599d commit 34638cb
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 34638cb

Please sign in to comment.