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

Two inits for the same contract #220

Closed
Tracked by #88
code423n4 opened this issue Oct 24, 2022 · 1 comment
Closed
Tracked by #88

Two inits for the same contract #220

code423n4 opened this issue Oct 24, 2022 · 1 comment
Labels
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 invalid This doesn't seem right primary issue Highest quality submission among a set of duplicates responded The Holograph team has reviewed and responded sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-10-holograph/blob/f8c2eae866280a1acfdc8a8352401ed031be1373/contracts/enforcer/PA1D.sol#L173-L198
https://github.com/code-423n4/2022-10-holograph/blob/f8c2eae866280a1acfdc8a8352401ed031be1373/contracts/enforcer/HolographERC721.sol#L259-L261

Vulnerability details

Impact

The PA1D contract have two function to initialize. The init and the initPA1D functions
The init sets _adminSlot, _ownerSlot and call setRoyalties but initPA1D function only call setRoyalties and don't initialize the _ownerSlot
As setRoyalties have onlyOwner modifier when the HolographERC721 call the initPA1D initialize reverts
Also the setRoyalties could be used by the owner without initialized restriction

Proof of Concept

init of HolographERC721 call initPA1D:

      (bool success, bytes memory returnData) = _royalties().delegatecall(
        abi.encodeWithSignature("initPA1D(bytes)", abi.encode(address(this), uint256(contractBps)))
      );

initPA1D of PA1D call setRoyalties:

  function initPA1D(bytes memory initPayload) external returns (bytes4) {
    uint256 initialized;
    assembly {
      initialized := sload(_initializedPaidSlot)
    }
    require(initialized == 0, "PA1D: already initialized");
    (address receiver, uint256 bp) = abi.decode(initPayload, (address, uint256));
    setRoyalties(0, payable(receiver), bp);
    initialized = 1;
    assembly {
      sstore(_initializedPaidSlot, initialized)
    }
    return InitializableInterface.init.selector;
  }

setRoyalties of PA1D have onlyOwner modifier:

  function setRoyalties(
    uint256 tokenId,
    address payable receiver,
    uint256 bp
  ) public onlyOwner {

Tools Used

Review

Recommended Mitigation Steps

Remove the initPA1D function and use only the init function

@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 gzeoneth marked this as a duplicate of #214 Oct 28, 2022
@gzeoneth gzeoneth added the duplicate This issue or pull request already exists label Oct 28, 2022
@gzeoneth gzeoneth reopened this Oct 28, 2022
@gzeoneth gzeoneth added primary issue Highest quality submission among a set of duplicates sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") and removed duplicate This issue or pull request already exists labels Oct 28, 2022
@alexanderattar
Copy link

init is used when deploying actual contract. All use of PA1D is via delegatecall, so the init is already called. initPA1D needs to be called to init even on deleatecall.

@alexanderattar alexanderattar added sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue responded The Holograph team has reviewed and responded and removed sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") labels Nov 8, 2022
@gzeoneth gzeoneth added the invalid This doesn't seem right label Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 invalid This doesn't seem right primary issue Highest quality submission among a set of duplicates responded The Holograph team has reviewed and responded sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Projects
None yet
Development

No branches or pull requests

3 participants