<!-- canonical: https://0xsimao.com/findings/glacier-avax-checking-earlier-gas -->

# In glAVAX, checking that amount > 0 earlier can save some gas

Low/Info · Three Sigma · Liquid staking · 12th July, 2023

Finding 3S-GLACIER-N09 of the Glacier security review.

- Protocol: https://www.glacier.io/
- Report: /reports/glacier
- Source: https://cdn.sanity.io/files/qoqld077/production/21bd3b6fa78c55968a6c9c7ea4fd49f34a8bd3d8.pdf

---

### Description

In the function withdraw() the function _borrowLiquidity() is called to borrow funds
from the lending pool if necessary. _borrowLiquidity() eventually calls _lendAvax() that
checks the following conditions if (amount > 0 && lendingBalance > 0). The condition
amount > 0 could be checked instead in the withdraw() function before calling
_borrowLiquity(), this would make it so that when amount == 0 no gas is spent going into
the function _borrowLiquidity().

### Recommendation

Put check before calling _borrowLiquidity():

```solidity
if( avaxAmount > 0) {
    avaxAmount = _borrowLiquidity(avaxAmount);
}
And remove check in _lendAvax(): if (lendingBalance > 0) {
```

### Status

Currently being reviewed by the team.

---

Related findings:

- [Late abond holders steal USDa amount from liquidations from earlier abond holders](https://0xsimao.com/findings/autonomint-abond-steal-liquidations-earlier): Autonomint
- [MapleLoan change the order of require to save on gas.](https://0xsimao.com/findings/maple-finance-iii-change-require-save-gas): Maple Finance
- [pool-v2-private: cache list length in memory and uncheck i_ to save gas.](https://0xsimao.com/findings/maple-finance-iii-private-cache-uncheck-gas): Maple Finance
- [open-term-loan-private: check dateFunded!=0 first to save gas.](https://0xsimao.com/findings/maple-finance-iii-term-date-funded-gas): Maple Finance
