SCWE-032: Dependency on Block Gas Limit
Stable Version v1.0
This content is in the version-(v1.0) and still under active development, so it is subject to change any time (e.g. structure, IDs, content, URLs, etc.).
Relationships¶
- CWE-400: Uncontrolled Resource Consumption
CWE-400 Link
Description¶
Dependency on block gas limit refers to the reliance on the Ethereum block gas limit for contract operations, which can lead to: - Failed transactions if gas limits are exceeded. - Exploitation of vulnerabilities in gas-intensive operations. - Loss of funds or data.
Remediation¶
- Optimize gas usage: Minimize gas consumption in contract operations.
- Avoid unbounded loops: Ensure loops have a fixed upper limit.
- Test thoroughly: Conduct extensive testing to ensure operations stay within gas limits.
Examples¶
- Gas-Intensive Operation- Storing Large Dynamic Data
- This contract appends large arrays in a single transaction, which fails when the block gas limit is exceeded.
-
Attackers could exploit this by forcing high gas consumption and causing DoS attacks (e.g., filling storage inefficiently).
-
Optimized Gas Usage- Chunk Processing & Gas Efficiency
Why is this better? - The start and end parameters allow batch processing instead of handling everything in a single call. - Prevents hitting the block gas limit by splitting work across multiple transactions.