The LibDiamond library implements the core functionality of the Diamond pattern, which uses a specific storage layout to manage upgradeable contracts. The key storage structure is defined as:
This storage is accessed using a specific storage position:
The Diamond contract uses a fallback function that employs delegatecall:
A malicious actor with the ability to add or modify facets could:
Create a facet with functions that directly manipulate the DiamondStorage structure.
Use the diamondCut function to add this malicious facet.
Call the malicious facet's function through the Diamond's fallback function.
For example, they could modify the selectorToFacetAndPosition
mapping to point existing selectors to a malicious facet, effectively hijacking contract functionality.
The impact of this vulnerability is severe:
Complete control over contract upgradeability
Ability to redirect any function call to malicious code
Potential to lock the contract by corrupting the storage structure
This could lead to theft of funds, permanent loss of contract functionality, or complete control of the contract by the attacker.
Manual
Implement strict access controls on the diamondCut function.
Add invariant checks in the LibDiamond functions to ensure critical storage (like selectorToFacetAndPosition
) isn't corrupted.
Consider implementing a time-lock or multi-sig requirement for upgrades.
Add functions to verify the integrity of the diamond storage after upgrades.
Thoroughly audit any new facets before adding them to the diamond.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.