<!-- canonical: https://0xsimao.com/findings/nftperp-i-structs-packed-save-gas -->

# Structs can be packed to save gas

Low/Info · Three Sigma · NFT perpetuals · 2nd January, 2024

Finding 3S-NFTPerp-N04 of the Nftperp Exchange security review.

- Report: /reports/nftperp-i
- Source: https://cdn.sanity.io/files/qoqld077/production/c19530de75e234ad15694b4563edb1fc9d2a3fd8.pdf

---

### Description

In solidity, structs can often be packed into fewer words to save gas on storage
loads/stores. In the [code](https://github.com/nftperp/NFTPerp-V2-Contracts/blob/1c16f2010a851ac23aec73822d55388901bbe5e7/src/nftperp-types/NFTPStructs.sol), the following structs can be optimized in this way: LimitOrder,
TriggerOrder, TwapInputAsset, MarketOrder.

### Recommendation

Reorder the variables in these structs to pack them together.

### Status

Acknowledged

---

Related findings:

- [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
- [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
