LAU-04C: Significant Optimization of Call Relays
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.
LAU-04C: Significant Optimization of Call Relays
Description:
The
LzAppUpgradeablecontract is meant to be an upgradeable version of theLzAppby LayerZero. To achieve this, its storage space has been migrated to a pointer-basedLzAppStoragestruct causing thelzEndpointto no longer beimmutableand require a fullSLOADoperation per-use.Example:
Recommendation:
We advise the
lzEndpointto be relocated to the contract itself and set as animmutablevariable. 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 theLzAppUpgradeable::constructorand utilized in the other functions of the contract viadelegatecalloperations.