String vs Bytes32 Storage Cost Comparator
Free to download on every platform. Comes pre-installed on BotFone, BotPad and BotFlip — with extra free apps included.
About this app
WHAT IT DOES
The String vs Bytes32 Storage Cost Comparator is a developer tool that analyzes Solidity source code to compare storage efficiency between string and bytes32 data types. It parses contract source to identify all state variables of these types and calculates estimated gas costs based on EVM storage rules. The tool highlights the critical difference: bytes32 always consumes exactly one storage slot, while string consumes one slot for short strings (≤31 bytes) but requires multiple slots for longer strings. This helps developers make informed decisions about which data type to use for identifiers, hashes, and short text storage.
HOW TO USE
Paste your Solidity contract source code into the analyzer. The tool processes the code, extracting all string and bytes32 state variables with their visibility modifiers. Results display in clear tables showing estimated gas costs per variable, storage slot usage, and specific recommendations. The tool provides side-by-side comparisons of both types, helping visualize the gas savings potential. A gas savings estimator calculates how much you could save by converting strings to bytes32 where appropriate.
TECHNICAL MECHANISM
The analyzer operates through static parsing of Solidity source code, first stripping comments and string literals to avoid false positives. It scans for state variables using regex patterns that distinguish between string, bytes32, and other types. The tool accounts for Solidity's storage optimization rules: strings of 31 bytes or less are stored in a single 32-byte slot (with the length encoded in the high-order byte), while strings of 32 bytes or more use one slot for the length and additional slots for the data. Bytes32 always uses exactly one slot regardless of content. The tool calculates estimated costs using standard EVM gas costs (20,000 gas per SSTORE, 100 gas per SLOAD) and provides recommendations based on the variable's type and typical usage patterns. The analysis includes a gas savings estimator that calculates potential optimization benefits based on the number of string variables that could be converted to bytes32.
WHAT IT CANNOT SEE
The tool cannot determine actual gas costs without executing the contract, as runtime string length variations significantly affect storage costs. It cannot account for dynamic string length variations at runtime or predict string assignment patterns. The tool cannot analyze memory vs storage costs for temporary strings that never persist to storage. It cannot detect string concatenation or manipulation costs, which often dominate gas usage. The tool cannot account for variable gas prices or analyze UTF-8 encoding overhead and validation costs. It cannot detect whether strings are actually used efficiently or identify opportunities for string packing or other optimizations.
PLEASE NOTE
This tool is designed for Ethereum Virtual Machine (EVM) compatible chains only. All gas estimations are approximations based on standard EVM storage costs and should be validated through testnet execution. The analysis assumes the Solidity compiler's default storage layout and may not account for custom optimizations or non-standard patterns. For critical applications, always verify storage costs through actual transaction execution on your target network. Consider the trade-off: bytes32 saves gas but cannot store UTF-8 encoded text or variable-length data, while string offers flexibility at a higher cost.