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

feat: protect protocol upgradeability loss #904

Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions packages/contracts/src/dollar/libraries/LibDiamond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ library LibDiamond {
_facetAddress != address(0),
"LibDiamondCut: Can't remove function that doesn't exist"
);
// precomputed diamondCut function selector to save gas
// bytes4(keccak256(abi.encodeWithSignature("diamondCut((address,uint8,bytes4[])[],address,bytes)"))) == 0x1f931c1c
require(
_selector != bytes4(0x1f931c1c),
rndquu marked this conversation as resolved.
Show resolved Hide resolved
"LibDiamondCut: Can't remove diamondCut function"
);
// an immutable function is a function defined directly in a diamond
require(
_facetAddress != address(this),
Expand Down
17 changes: 17 additions & 0 deletions packages/contracts/test/diamond/DiamondTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,23 @@ contract TestDiamond is DiamondTestSetup {
IMockFacet(address(diamondCutFacet)).functionB();
}

function testCutFacetShouldNotRemoveDiamondCutFunction() public {
FacetCut[] memory facetCut = new FacetCut[](1);
bytes4[] memory selectors = new bytes4[](1);
selectors[0] = diamondCutFacet.diamondCut.selector;

facetCut[0] = FacetCut({
facetAddress: address(0),
action: FacetCutAction.Remove,
functionSelectors: selectors
});

// try to remove diamondCut function
vm.prank(owner);
vm.expectRevert("LibDiamondCut: Can't remove diamondCut function");
diamondCutFacet.diamondCut(facetCut, address(0x0), "");
}

function testSelectors_ShouldBeAssociatedWithCorrectFacet() public {
for (uint256 i; i < facetAddressList.length; i++) {
if (compareStrings(facetNames[i], "DiamondCutFacet")) {
Expand Down
Loading