Recall & Review
beginner
What is variable packing in blockchain smart contracts?
Variable packing is the technique of grouping multiple smaller variables into a single storage slot to reduce gas costs by minimizing storage usage.
Click to reveal answer
beginner
Why does packing variables save gas in Ethereum smart contracts?
Because Ethereum charges gas based on storage slots used, packing multiple small variables into one 32-byte slot reduces the number of slots, lowering gas consumption.
Click to reveal answer
intermediate
Which data types are best suited for packing together?
Smaller data types like uint8, bool, or bytes1 can be packed together efficiently since they take less than 32 bytes each and fit into one storage slot.
Click to reveal answer
intermediate
What happens if variables are declared out of order for packing?
If variables are not ordered from smallest to largest, the compiler may not pack them efficiently, causing more storage slots to be used and increasing gas costs.
Click to reveal answer
beginner
Show an example of packing two uint128 variables in Solidity.
```solidity
contract Packed {
uint128 a;
uint128 b;
}
```
Here, both uint128 variables fit into one 32-byte storage slot, saving gas.
Click to reveal answer
Why is packing variables important in Ethereum smart contracts?
✗ Incorrect
Packing variables reduces the number of storage slots used, which lowers gas costs.
Which of these variable types can be packed together efficiently?
✗ Incorrect
Small types like uint8 and bool fit together in one storage slot, saving gas.
What is the size of one storage slot in Ethereum?
✗ Incorrect
Each storage slot in Ethereum is 32 bytes.
What is a common mistake that reduces packing efficiency?
✗ Incorrect
Declaring variables out of size order can prevent efficient packing.
How many uint128 variables can fit in one storage slot?
✗ Incorrect
Two uint128 variables (16 bytes each) fit into one 32-byte storage slot.
Explain how packing variables can reduce gas costs in Ethereum smart contracts.
Think about how Ethereum charges for storage and how combining variables helps.
You got /3 concepts.
Describe best practices for ordering variables to maximize packing efficiency.
Consider how variable size affects packing in storage slots.
You got /3 concepts.