- Solidity version <0.4.22 where constructors are named functions matching the contract name
// Solidity <0.4.22: constructor is a named function
contract Owned {
address public owner;
// Typo: "owned" != "Owned" (case mismatch)
// This becomes a regular public function anyone can call
function owned() public {
owner = msg.sender;
}
}
// Contract renamed but constructor not updated
contract Treasury {
address public owner;
// Was "Wallet" before rename — now a regular public function
function Wallet() public {
owner = msg.sender;
}
}
constructor keyword is used, this vulnerability does not applyowner or perform one-time initialization — these may be misnamed constructorsconstructor keyword (enforced by compiler)constructor keyword// Modern Solidity: compiler-enforced constructor
contract Owned {
address public owner;
constructor() {
owner = msg.sender;
}
}