Blog

Uninitialized Storage Pointers/ Uninitialized State Bugs Explained

In Solidity, data storage is categorized into three main types: storage, memory, and calldata, each serving distinct purposes within smart contracts.

Storage variables are part of the contract's persistent state as they retain their values across function calls and transactions but are more expensive to read and write due to blockchain storage costs.

Memory variables, on the other hand, are temporary and exist only during the execution of a function. They are not stored on the blockchain, making them faster and cheaper to use.

Memory is typically used for local variables within functions, function parameters, and return values. Calldata is another temporary data location used specifically for function arguments in external functions. It is read-only and more efficient for passing large data arrays.




In the example above, when the calculate function is called, it temporarily creates memoryVariable, performs the calculation using storageVariable and the provided _value, and then returns the result. However, memoryVariable does not exist outside this function call.

With this foundation laid, let us dive into the concept of storage pointers in the next post.