DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: low
Invalid

L-3 Use selfbalance() instead of address(this).balance in GmxProxy.sol

Summary

In Solidity, contracts often check their own Ether balance. While address(this).balance is common, it’s not the most gas-efficient way.

The SELFBALANCE opcode, accessible via selfbalance(), is a cheaper alternative:

  • BALANCE costs 100–2,600 gas, depending on the address state.

  • SELFBALANCE does the same but with a fixed 5-gas cost.

Using selfbalance() can significantly reduce gas costs in balance checks.

119: if (address(this).balance >= minEth) return false;
381: address(this).balance >= positionExecutionFee,
469: address(this).balance >= positionExecutionFee,
540: uint256 balance = address(this).balance;

Recommendations

For better gas efficiency in Solidity, use selfbalance() instead of address(this).balance. It leverages the SELFBALANCE opcode, reducing gas costs significantly.

Updates

Lead Judging Commences

n0kto Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.