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

_verifySigner check can be bypassed #199

Closed
code423n4 opened this issue Oct 24, 2022 · 2 comments
Closed

_verifySigner check can be bypassed #199

code423n4 opened this issue Oct 24, 2022 · 2 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-10-holograph/blob/main/contracts/HolographFactory.sol#L320-L335
https://github.com/code-423n4/2022-10-holograph/blob/main/contracts/HolographFactory.sol#L220

Vulnerability details

Description

The current implementation of the _verifySigner function is insufficient and can be bypassed.

When _verifySigner function is called, ecrecover will return address(0) if the signature is invalid.
As a result, the requirement of _verifySigner call in HolographFactory.deployHolographableContract() can bypassed by sending an invalid signature and assigning signer = 0x0

There is no immediate issue currently that I've noticed as this will result in the hash being different and resulting in a different holographerAddress, an attacker wouldn't be able to take over a holographer deployed address.

However, future implementation that would utilize the _verifySigner check can potentially be vulnerable if not implemented correctly.

Proof of Concept

function _verifySigner(
    bytes32 r,
    bytes32 s,
    uint8 v,
    bytes32 hash,
    address signer
  ) private pure returns (bool) {
    if (v < 27) {
      v += 27;
    }
    /**
     * @dev signature is checked against EIP-191 first, then directly, to support legacy wallets
     */
    return (ecrecover(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)), v, r, s) == signer ||
      ecrecover(hash, v, r, s) == signer);
}

https://github.com/code-423n4/2022-10-holograph/blob/main/contracts/HolographFactory.sol#L320-L335

require(_verifySigner(signature.r, signature.s, signature.v, hash, signer), "HOLOGRAPH: invalid signature");

https://github.com/code-423n4/2022-10-holograph/blob/main/contracts/HolographFactory.sol#L220

Recommended Mitigation Steps

I advise an additional check to be imposed within _verifySigner that ensures the signer or the results of ecrecover is not the zero-address which will alleviate this check. For more details, consult the EIP721 implementation by OpenZeppelin ( https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.0/contracts/cryptography/ECDSA.sol#L53-L71).

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Oct 24, 2022
code423n4 added a commit that referenced this issue Oct 24, 2022
@gzeoneth
Copy link
Member

Duplicate of #357

@gzeoneth gzeoneth marked this as a duplicate of #357 Oct 30, 2022
@gzeoneth gzeoneth added the duplicate This issue or pull request already exists label Oct 30, 2022
@gzeoneth gzeoneth added QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Nov 21, 2022
@gzeoneth
Copy link
Member

Consider with #68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Projects
None yet
Development

No branches or pull requests

2 participants