Skip to content

Latest commit

 

History

History
17 lines (11 loc) · 1.17 KB

SWC-118.md

File metadata and controls

17 lines (11 loc) · 1.17 KB

Title

Incorrect Constructor Name

Relationships

CWE-665: Improper Initialization

Description

Constructors are special functions that are called only once during the contract creation. They often perform critical, privileged actions such as setting the owner of the contract. Before Solidity version 0.4.22, the only way of defining a constructor was to create a function with the same name as the contract class containing it. A function meant to become a constructor becomes a normal, callable function if its name doesn't exactly match the contract name. This behavior sometimes leads to security issues, in particular when smart contract code is re-used with a different name but the name of the constructor function is not changed accordingly.

Remediation

Solidity version 0.4.22 introduces a new constructor keyword that make a constructor definitions clearer. It is therefore recommended to upgrade the contract to a recent version of the Solidity compiler and change to the new constructor declaration.

References