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

refactor: respond to PR comment by 0xbok #198

Merged
merged 2 commits into from
Oct 7, 2024
Merged
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
44 changes: 12 additions & 32 deletions contracts/modules/validators/K1Validator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,6 @@ contract K1Validator is IValidator, ERC7739Validator {
return _validateSignatureForOwner(owner, hash, sig);
}

/// @notice Recovers the signer from a signature
/// @param hash The hash of the data to validate
/// @param signature The signature data
/// @return The recovered signer address
function recoverSigner(bytes32 hash, bytes calldata signature) external view returns (address) {
return hash.recover(signature);
}

/// @notice Recovers the signer from an Ethereum signed message
/// @param hash The hash of the data to validate
/// @param signature The signature data
/// @return The recovered signer address
function recoverSignerFromEthSignedMessage(bytes32 hash, bytes calldata signature) external view returns (address) {
return hash.toEthSignedMessageHash().recover(signature);
}

/*//////////////////////////////////////////////////////////////////////////
METADATA
//////////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -214,6 +198,15 @@ contract K1Validator is IValidator, ERC7739Validator {
INTERNAL
//////////////////////////////////////////////////////////////////////////*/

/// @notice Recovers the signer from a signature
/// @param hash The hash of the data to validate
/// @param signature The signature data
/// @return The recovered signer address
/// @notice tryRecover returns address(0) on invalid signature
function _recoverSigner(bytes32 hash, bytes calldata signature) internal view returns (address) {
return hash.tryRecover(signature);
}

/// @dev Returns whether the `hash` and `signature` are valid.
/// Obtains the authorized signer's credentials and calls some
/// module's specific internal function to validate the signature
Expand Down Expand Up @@ -252,22 +245,9 @@ contract K1Validator is IValidator, ERC7739Validator {
}

// verify signer
try this.recoverSigner(hash, signature) returns (address recoveredSigner) {
if (recoveredSigner == owner) {
return true;
}
} catch {
// If recovery fails, we'll continue to the next check
}

try this.recoverSignerFromEthSignedMessage(hash, signature) returns (address recoveredSigner) {
if (recoveredSigner == owner) {
return true;
}
} catch {
// If recovery fails, we'll return false
}

// owner can not be zero address in this contract
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I thought we had zero address check in place. I think we can enforce this in onInstall and create informational issue. @0xbok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (_recoverSigner(hash, signature) == owner) return true;
if (_recoverSigner(hash.toEthSignedMessageHash(), signature) == owner) return true;
return false;
}

Expand Down
Loading