SCWE-082: Lack of Proper Gas Management
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
https://cwe.mitre.org/data/definitions/400.html
Description¶
Gas management is crucial in smart contracts to ensure that they do not run out of gas or cause excessive consumption. If gas consumption is not properly controlled, a contract can fail to execute or can be exploited by attackers to cause denial of service (DoS).
Remediation¶
Properly estimate the gas required for functions and set appropriate gas limits. Use require or other mechanisms to handle gas consumption failures and ensure that gas usage remains within acceptable bounds.
Vulnerable Contract Example¶
contract Example {
function execute() public {
while (true) {
// Excessive gas consumption, no limit set
}
}
}