🟠2. Medium - Interview Questions
2.1 What is the difference between transfer and send?
send
Returns a bool indicating success (true) or failure (false).
Only forwards a fixed 2300 gas stipend, which is often enough for basic operations but might not suffice for complex logic in the receiving contract.
If the transfer fails, it does not revert the transaction. You need to handle the failure by checking the return value.
transfer
Automatically reverts the transaction if the transfer fails, so no additional error handling is needed.
Also forwards a fixed 2300 gas stipend, preventing the receiving contract from executing too much code.
Generally considered safer because it reverts on failure, meaning you don’t have to manually check for success.
2.2 Why should they not be used?
Due to the fixed gas limits, they are not flexible enough to work with smart contract wallets which may require more gas than is available from transfer
or send
.
2.3 What is a storage collision in a proxy contract?
When a function in the proxy contract has the same 4-byte identifier as a function in the implementation contract. This will cause a collision and mean that the function in the implementation contract can never be called.
2.4 What is the difference between abi.encode and abi.encodePacked?
abi.encode
Encodes data in ABI (Application Binary Interface) encoding format.
Adds padding to make each data item fit into a 32-byte slot, following the ABI encoding standards.
Each argument is encoded as a standalone item, with proper padding and alignment, which makes it more readable and less error-prone when used in conjunction with other Solidity functions.
Example:
Input:
bytes memory encodedData = abi.encode("Hello", uint256(123));
Output (encodedData):
0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000000548656c6c6f000000000000000000000000000000000000000000000000000000
(padded to 32 bytes).
abi.encodePacked
Encodes data in a compact, non-standard format.
Does not add padding, so each data item is placed directly after the previous one without any alignment.
Generally used for more compact encoding or for concatenating data, such as when creating a unique hash (e.g., in keccak256 hashing).
Be careful with potential collisions:
Concatenating variable-length types (like string and bytes) without padding can result in ambiguous results. For example, encoding two strings with abi.encodePacked("abc", "def") and abi.encodePacked("ab", "cdef") would produce the same output.
Example:
Input:
bytes memory packedData = abi.encodePacked("Hello", uint256(123));
Output (packedData):
0x48656c6c6f000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000
(no padding).
2.5 uint8, uint32, uint64, uint128, uint256 are all valid uint sizes. Are there others?
2.6 What changed with block.timestamp before and after proof of stake?
2.7 What is frontrunning?
2.8 What is a commit-reveal scheme and when would you use it?
2.9 Under what circumstances could abi.encodePacked create a vulnerability?
2.10 How does Ethereum determine the BASEFEE in EIP-1559?
2.11 What is the difference between a cold read and a warm read?
2.12 How does an AMM price assets?
2.13 What is a function selector clash in a proxy and how does it happen?
2.14 What is the effect on gas of making a function payable?
2.15 What is a signature replay attack?
2.16 How would you design a game of rock-paper-scissors in a smart contract such that players cannot cheat?
2.17 What is the free memory pointer and where is it stored?
0x40
2.18 What function modifiers are valid for interfaces?
2.19 What is the difference between memory and calldata in a function argument?
2.20 Describe the three types of storage gas costs for writes.
2.21 Why shouldn’t upgradeable contracts use the constructor?
2.22 What is the difference between UUPS and the Transparent Upgradeable Proxy pattern?
2.23 If a contract delegatecalls an empty address or an implementation that was previously self-destructed, what happens?
2.24 What if it is a low-level call instead of a delegatecall?
2.25 What danger do ERC777 tokens pose?
2.26 According to the solidity style guide, how should functions be ordered?
2.27 According to the solidity style guide, how should function modifiers be ordered?
2.28 What is a bonding curve?
2.29 How does _safeMint differ from _mint in the OpenZeppelin ERC721 implementation?
2.30 What keywords are provided in Solidity to measure time?
2.31 What is a sandwich attack?
2.32 If a delegatecall is made to a function that reverts, what does the delegatecall do?
2.33 What is a gas efficient alternative to multiplying and dividing by a power of two?
2.34 How large a uint can be packed with an address in one slot?
2.35 Which operations give a partial refund of gas?
2.36 What is ERC165 used for?
2.37 If a proxy makes a delegatecall to A, and A does address(this).balance, whose balance is returned, the proxy’s or A?
2.38 What is a slippage parameter useful for?
2.39 What does ERC721A do to reduce mint costs? What is the tradeoff?
2.40 Why doesn’t Solidity support floating point arithmetic?
2.41 What is TWAP? How does Compound Finance calculate utilization?
2.42 If a delegatecall is made to a function that reads from an immutable variable, what will the value be?
2.43 What is a fee-on-transfer token?
2.44 What is a rebasing token?
2.45 In what year will a timestamp stored in a uint32 overflow?
2.46 What is LTV in the context of DeFi?
2.47 What are aTokens and cTokens in the context of Compound Finance and AAVE?
2.48 Describe how to use a lending protocol to go leveraged long or leveraged short on an asset.
2.49 What is a perpetual protocol?
Last updated