Skip to content
This repository has been archived by the owner on Jul 14, 2024. It is now read-only.

XDZIBEC - Reentrancy Vulnerability in EIP-2535 Diamond Standard Implementation #119

Closed
sherlock-admin opened this issue Jan 10, 2024 · 4 comments · Fixed by ubiquity/ubiquity-dollar#918
Labels
Excluded Excluded by the judge without consulting the protocol or the senior Non-Reward This issue will not receive a payout Sponsor Disputed The sponsor disputed this issue's validity Won't Fix The sponsor confirmed this issue will not be fixed

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Jan 10, 2024

XDZIBEC

high

Reentrancy Vulnerability in EIP-2535 Diamond Standard Implementation

Summary

The contract is Standard allows for modular contract development using the "facet" pattern, which can lead to complex interactions between different parts of the contract and it's contain a reentrancy vulnerability from the missing of the nonReentrant modifier.

Vulnerability Detail

The contract use fallback function and employs delegatecall to forward external calls to addresses determined by the selectorToFacetAndPosition mapping and this setup presents a risk of reentrancy attacks, because the contract itself does not have a reentrancy guard. This means each facet, especially those with state-changing and payable functions, must independently implement reentrancy protection measures. If these facets lack appropriate guards, they can be vulnerable to reentrancy attacks. In such attacks, an adversary could exploit the absence of reentrancy protection to perform unexpected state changes or asset transfers by recursively calling the function.
here is the vulnerable part :

fallback() external payable {
        LibDiamond.DiamondStorage storage ds;
        bytes32 position = LibDiamond.DIAMOND_STORAGE_POSITION;
        assembly {
            ds.slot := position
        }
        address facet = ds.selectorToFacetAndPosition[msg.sig].facetAddress;
        require(facet != address(0), "Diamond: Function does not exist");
        assembly {
            calldatacopy(0, 0, calldatasize())
            let result := delegatecall(gas(), facet, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch result
            case 0 {
                revert(0, returndatasize())
            }
            default {
                return(0, returndatasize())
            }
        }
    }
}

An attacker can potentially leverage this vulnerability to manipulate contract states or extract funds,

Impact

Without reentrancy guards, an attacker could potentially exploit this vulnerability and manipulate the contract's state and then can drain funds.
This is especially risk for state-changing and payable functions within the facets.

Code Snippet

Tool used

Manual Review

Recommendation

need to add the nonReentrant modifier on the fallback function.

@github-actions github-actions bot added the Excluded Excluded by the judge without consulting the protocol or the senior label Jan 14, 2024
@sherlock-admin2
Copy link
Contributor

1 comment(s) were left on this issue during the judging contest.

auditsea commented:

Not seeing any re-entrancy attack vectors from current codebase. Even though there is, it will be block at implementation, not entirely on fallback

1 similar comment
@sherlock-admin2
Copy link
Contributor

1 comment(s) were left on this issue during the judging contest.

auditsea commented:

Not seeing any re-entrancy attack vectors from current codebase. Even though there is, it will be block at implementation, not entirely on fallback

@molecula451 molecula451 removed the Excluded Excluded by the judge without consulting the protocol or the senior label Jan 19, 2024
@molecula451
Copy link

Re-opening to check things on the standard-2535

@molecula451 molecula451 reopened this Jan 19, 2024
@nevillehuang
Copy link
Collaborator

Invalid, insufficient proof that reentrancy can occur.

@molecula451 molecula451 added the Excluded Excluded by the judge without consulting the protocol or the senior label Jan 19, 2024
@sherlock-admin sherlock-admin changed the title Sparkly Taffy Shark - Reentrancy Vulnerability in EIP-2535 Diamond Standard Implementation XDZIBEC - Reentrancy Vulnerability in EIP-2535 Diamond Standard Implementation Jan 24, 2024
@sherlock-admin sherlock-admin added the Non-Reward This issue will not receive a payout label Jan 24, 2024
@sherlock-admin2 sherlock-admin2 added Sponsor Disputed The sponsor disputed this issue's validity Won't Fix The sponsor confirmed this issue will not be fixed labels Feb 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Excluded Excluded by the judge without consulting the protocol or the senior Non-Reward This issue will not receive a payout Sponsor Disputed The sponsor disputed this issue's validity Won't Fix The sponsor confirmed this issue will not be fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants