Blockchain
Architecting Gas-Optimised Smart Contracts for Multi-Chain Deployments
Storage layout, calldata, custom errors and transient storage: the practical levers that reduce transaction costs on EVM networks — and why none of them replace security work.
Kizoona Studio7 min read
On EVM networks, every operation a contract performs has a cost that users pay. Gas efficiency is therefore not only a technical nicety: it shapes how often people interact with a protocol and which actions are economically sensible at all.
Storage is the expensive part
Writing to and reading from contract storage are among the most expensive operations available. Variables that are read or written together can often be packed into a single 32-byte slot, and values that never change after deployment belong in constant or immutable variables rather than storage.
Calldata, memory and loops
For external functions that receive arrays or structs they do not modify, calldata avoids an unnecessary copy into memory. Inside loops, caching a storage value in a local variable avoids paying for the same read repeatedly. Unbounded loops over user-controlled data should be avoided entirely, because they can make a function impossible to execute as the data grows.
Custom errors and events
Since Solidity 0.8.4, custom errors provide descriptive failures at a lower deployment and runtime cost than long revert strings. Data that only needs to be read off-chain — by an indexer or an interface — is usually better emitted as an event than stored.
Transient storage
EIP-1153 introduced transient storage, which is cleared at the end of each transaction. It suits values that only matter within a single transaction, such as re-entrancy locks. Support varies between networks, so it should be confirmed for every chain a contract targets.
Measure, then optimise
Foundry's gas snapshots and reports make the effect of each change visible. We keep optimisations readable and documented, and use unchecked arithmetic only where overflow is provably impossible.
Optimisation never replaces security
Efficient code that is wrong is still wrong. Our smart-contract work combines unit, fuzz and invariant testing in Foundry with static analysis such as Slither, and we recommend independent audits for any contract that will hold user funds.