NFTBridge
60,000 USDC
View results
Submission Details
Severity: medium
Invalid

The initialize function can lead to a state where the contract becomes partially initialized and unable to be re-initialized

Summary

The initialize function can lead to a state where the contract becomes partially initialized and unable to be re-initialized.

Vulnerability Details

The onlyInit modifier sets the implementation as initialized (_initializedImpls[impl] = true) before the actual initialization code in the initialize function is executed.

// onlyInit
modifier onlyInit() {
address impl = _getImplementation();
require(!_initializedImpls[impl], "Already init");
_initializedImpls[impl] = true;
_;
}

https://github.com/Cyfrin/2024-07-ark-project/blob/273b7b94986d3914d5ee737c99a59ec8728b1517/apps/blockchain/ethereum/src/UUPSProxied.sol#L19C2-L26C6

If the initialize function fails or reverts after the modifier has run but before completing all initialization steps, the contract will be left in a partially initialized state and cannot be re-initialized.

https://github.com/Cyfrin/2024-07-ark-project/blob/273b7b94986d3914d5ee737c99a59ec8728b1517/apps/blockchain/ethereum/src/Bridge.sol#L44C4-L67C1

Impact

Denial of service as it becomes impossible to properly initialize the contract after a failed initialization attempt.

Tools Used

Manual review

Recommendations

Modify the onlyInit modifier to only check if the implementation is initialized, without setting it as initialized.

modifier onlyInit() {
address impl = _getImplementation();
require(!_initializedImpls[impl], "Already init");
_;
}

Move the initialization flag setting to the end of the initialize function:

function initialize(bytes calldata data) public onlyInit {
// ... (rest of the initialization code)
// Add this at the end of the function
address impl = _getImplementation();
_initializedImpls[impl] = true;
}
Updates

Lead Judging Commences

n0kto Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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