DeFiFoundry
60,000 USDC
View results
Submission Details
Severity: low
Valid

Failing initialization of contracts

Summary

GlobalConfigurationBranch & UpgradeBranchimplement initialize() functions that reference the same initializer storage slot, meaning that if one of the initialziers is called the other one would fail.

Vulnerability Details

GlobalConfigurationBranch & UpgradeBranch both have initialize() functions and are both inherited in the PerpsEnginewhich is the RootProxy, meaning they share the same storage:


Both contracts inherit Initializable from OZ, which defines the following storage logic:

struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

This means that both contracts reference the same InitializableStorage._initialized variable inside the Proxy. As a result if GlobalConfigurationBranch calls initialize()it will succeed, but calling UpgradeBranch.initialize()after that will revert, since the first initialization call would update InitializableStorage._initialized to true.

Tools Used

Manual Review

Recommendations

Since all contracts share the same Proxy (Diamond Proxy) instead each having it's separate proxy, storage is shared. This means that initialization function (with initializer modifier) can be only one.

Consider moving all the initialization logic either to UpgradeBranch or to GlobalConfigurationBranch. This way initialize() would be called only once and it will succeed.

Updates

Lead Judging Commences

inallhonesty Lead Judge 11 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Appeal created

inallhonesty Lead Judge
10 months ago
inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Validated
Assigned finding tags:

`initializer` modifiers will revert if not deployed in the same constructor

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.