TangibleTNFT / ustb

MIT License
0 stars 1 forks source link

[LAU-04C] Significant Optimization of Call Relays #11

Open dkuppitz opened 11 months ago

dkuppitz commented 11 months ago

LAU-04C: Significant Optimization of Call Relays

Type Severity Location
Gas Optimization LzAppUpgradeable.sol:L51, L93

Description:

The LzAppUpgradeable contract is meant to be an upgradeable version of the LzApp by LayerZero. To achieve this, its storage space has been migrated to a pointer-based LzAppStorage struct causing the lzEndpoint to no longer be immutable and require a full SLOAD operation per-use.

Example:

/// @custom:storage-location erc7201:layerzero.storage.LzApp
struct LzAppStorage {
    ILayerZeroEndpoint lzEndpoint;
    mapping(uint16 => bytes) trustedRemoteLookup;
    mapping(uint16 => mapping(uint16 => uint256)) minDstGasLookup;
    mapping(uint16 => uint256) payloadSizeLimitLookup;
    address precrime;
}

Recommendation:

We advise the lzEndpoint to be relocated to the contract itself and set as an immutable variable. Immutable variables are upgradeability-compatible as they are placed within the bytecode of the contract rather than its storage space, meaning that they can safely be set in the LzAppUpgradeable::constructor and utilized in the other functions of the contract via delegatecall operations.

dkuppitz commented 11 months ago

That was a great suggestion. Resolved in 59f1e4355ddef7e93a755e7b2311eb0c7bb0177c.