Solidity is an object-oriented, high-level programming language for implementing smart contracts on various blockchain platforms, most notably Ethereum. It was influenced by C++, Python, and JavaScript and is designed to target the Ethereum Virtual Machine (EVM).
Solidity Anti-Patterns Overview
Reentrancy Vulnerabilities
Unchecked External Calls
send()
, call()
, and delegatecall()
. These functions return a boolean indicating success or failure, and ignoring this value can lead to silent failures.Integer Overflow and Underflow
unchecked
blocks carefully for gas optimization.Improper Access Control
Timestamp Dependence
block.timestamp
for critical logic, as miners can manipulate it slightly. For applications requiring precise timing, consider using block numbers instead or be aware of the potential for small timestamp manipulations.Improper Use of tx.origin
tx.origin
for authorization, as it makes your contract vulnerable to phishing attacks. Use msg.sender
instead to verify the immediate caller of your contract.Unbounded Loops
Incorrect Inheritance Order
super
calls are resolved from right to left. Incorrect inheritance order can lead to unexpected behavior.Excessive Gas Consumption
unchecked
blocks for simple arithmetic operations when overflow/underflow is not a concern.Hardcoded Addresses
Lack of Event Emissions
Improper Decimals Handling
Unprotected Self-Destruct
selfdestruct
function with proper access control. An unprotected selfdestruct
can allow anyone to destroy your contract and steal its funds.Incorrect Use of Cryptography
block.timestamp
or block.difficulty
for randomness, as they can be manipulated by miners. For applications requiring randomness, use a commit-reveal scheme, oracles, or VRF (Verifiable Random Function) services like Chainlink VRF.Lack of Input Validation
Not Using SafeERC20
transfer()
or approve()
calls, which can cause your transactions to revert unexpectedly.