<!-- canonical: https://0xsimao.com/findings/maple-finance-iii-change-require-save-gas -->

# MapleLoan change the order of require to save on gas.

Low/Info · Three Sigma · Institutional lending · 10th April, 2024

Finding 3S-MAPLE-N03 of the Maple Finance security review.

- Protocol: https://maple.finance/
- Report: /reports/maple-finance-iii-2024
- Source: https://cdn.sanity.io/files/qoqld077/production/36dbe5ca76da3d2392bcee581548067705b8bd36.pdf

---

### Description

On open-term-loan/MapleLoan.sol, line 84 of acceptNewTerms(), there is a require to
check that the refinance commitment according to the terms sent by the user is valid and
to do so refinanceCommitment is loaded from storage. Then, on lines 88 and 89 additional
checks are made regarding the arguments previously used.

### Recommendation

If these checks were to be done before, in the case of invalid arguments, it would save gas
by not having to load refinanceCommitment from storage.

### Status

Addressed in the following PR:
https://github.com/maple-labs/open-term-loan-private/pull/56

---

Related findings:

- [Custom errors should be used instead of require() statements to save gas](https://0xsimao.com/findings/metazero-ii-custom-require-statements-gas): MetaZero Staking
- [In glAVAX, checking that amount > 0 earlier can save some gas](https://0xsimao.com/findings/glacier-avax-checking-earlier-gas): Glacier
- [Storage variables should be cached whenever possible to save gas](https://0xsimao.com/findings/glacier-storage-cached-whenever-gas): Glacier
- [genesisLimit can be placed as constant variables to save gas.](https://0xsimao.com/findings/metazero-i-genesis-placed-constant-gas): MetaZero Omnichain NFTs
