Eridian
eridian.xyzx.comGitHub
  • 📖Eridian Docs
  • Ethereum Dev
    • ✏️Ethereum Notes
      • 🎛️Technical Basics
      • 🪧Ethereum Addresses
      • 📚Ethereum State Explained
      • ⛽Gas Fees Explained
    • 🔧Useful Tools
      • ☁️Ethers
      • *️⃣Ethernal
    • 📝Solidity Notes
      • ❔Interview Questions
        • 🟢1. Easy - Interview Questions
        • 🟠2. Medium - Interview Questions
        • 🟡3. Hard - Interview Questions
        • 🔴4. Advanced - Interview Questions
      • 💡Note Ideas
      • ABI
      • abi.encodePacked
      • Abstract Contracts
      • Arrays
      • Casting
      • CEI - Checks, Effects, Interactions
      • Comments (NATSPEC)
      • Constructor
      • Contract Structure & Versions
      • Data - Storage vs Memory
      • Data - Storage Layout
      • Enum
      • Errors (require & revert)
      • Events
      • EVM Opcodes
      • External Contract Interaction
      • 🏗️External Dependencies
      • Functions
      • Function Modifiers
      • If / Else / For / While Loops
      • Inheritance
      • Interfaces
      • Keccak256
      • Library
      • Mappings
      • msg.sender
      • Objects & Types
      • OpenZeppelin
      • Payable
      • Public State Variable vs Function
      • Receive & Fallback
      • Security
      • Self Destruct
      • Send ETH (transfer, send, call)
      • Stack Too Deep
      • Structs
      • Style Guide
      • Time Units
      • Try / Catch
      • Typecasting
      • Using Directive
      • Variables, Consts & Immutable
      • Withdraws
    • ⚒️Foundry Notes
      • 📖Docs & GitHub Pages
      • 🤝Useful Commands
        • 🔨Anvil
        • 🪄Cast
        • 🔥Forge
      • 🧪Tests
        • Cheatcodes
      • 📝Useful Scripts
        • Deploy Contract Using Hex
    • 👾DeFi Challenges
      • 👨‍🚀Ethernaut
        • Ethernaut - Template
        • Level 1 - Fallback ⏺
        • Level 2 - Fallout ⏺
        • Level 3 - Coin Flip ⏺⏺
        • Level 4 - Telephone ⏺
        • Level 5 - Token ⏺⏺
        • Level 6 - Delegation ⏺⏺
        • Level 7 - Force ⏺⏺⏺
        • Level 8 - Vault ⏺⏺
        • Level 9 - King ⏺⏺⏺
        • Level 10 - Re-entrancy ⏺⏺⏺
        • Level 11 - Elevator ⏺⏺
        • Level 12 - Privacy ⏺⏺⏺
        • Level 13 - Gatekeeper 1 ⏺⏺⏺⏺
        • Level 14 - Gatekeeper 2 ⏺⏺⏺
        • Level 15 - Naught Coin ⏺⏺⏺
        • Level 16 - Preservation ⏺⏺⏺⏺
        • Level 17 - Recovery ⏺⏺⏺
        • Level 18 - Magic Number ⏺⏺⏺
        • Level 19 - Alien Codex ⏺⏺⏺⏺
        • Level 20 - Denial ⏺⏺⏺
        • Level 21 - Shop ⏺⏺
        • Level 22 - Dex ⏺⏺
        • Level 23 - Dex Two ⏺⏺
        • Level 24 - Puzzle Wallet ⏺⏺⏺⏺
        • Level 25 - Motorbike ⏺⏺⏺
        • Level 26 - DoubleEntryPoint ⏺⏺
        • Level 27 - Good Samaritan ⏺⏺⏺
        • Level 28 - Gatekeeper 3 ⏺⏺⏺
        • Level 29 - Switch ⏺⏺⏺⏺
        • Level 30 - Higher Order ⏺⏺⏺⏺
        • Level 31 - Stake ⏺⏺⏺
      • 💸Damn Vulnerable DeFi
    • 🔍Auditing
      • 🗞️Exploit Resources
      • 🔧Audit Tools
    • 🤖MEV
  • Infrastructure Docs
    • 💻Hardware
    • 🐧Linux
      • 📖Linux Glossary
      • ⌨️Linux Commands
      • 💾Installation
      • 🏗️Maintenance
      • 🖥️Ubuntu Desktop
      • 🛜ZeroTier
      • 🎞️TMUX
      • 🔵Bluetooth
    • ⛓️Ethereum Clients
      • ⚙️Execution Clients
        • ⛏️Geth
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
        • 🐻Erigon
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
        • 🧶Besu
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • 🤝Beacon Clients
        • 💡Lighthouse
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
        • 🪅Teku
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • 💎Validator Clients
        • 💡Lighthouse
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • ➕L2 Clients
        • 🔵Base
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • 💰MEV Boost
        • 💾Installation
        • 🏗️Maintenance
    • 🚨Alerting and Monitoring
      • 🔥Prometheus
      • 🌡️HealthChecks.io
      • 📟PagerDuty
  • General Dev
    • 💾Git Notes
      • Repos
      • Committing changes
      • Branches
      • Merging & Rebasing
      • PRs
Powered by GitBook
On this page
  • 1.1. What is the difference between private, internal, public, and external functions?
  • 1.2. Approximately, how large can a smart contract be?
  • 1.3. What is the difference between create and create2?
  • 1.4. What major change with arithmetic happened with Solidity 0.8.0?
  • 1.5. What special CALL is required for proxies to work?
  • 1.6. How do you calculate the dollar cost of an Ethereum transaction?
  • 1.7. What are the challenges of creating a random number on the blockchain?
  • 1.8. What is the difference between a Dutch Auction and an English Auction?
  • 1.9. What is the difference between transfer and transferFrom in ERC20?
  • 1.10. Which is better to use for an address allowlist: a mapping or an array?
  • 1.11. Why shouldn’t tx.origin be used for authentication?
  • 1.12. What hash function does Ethereum primarily use?
  • 1.13. How much is 1 gwei of Ether? How much is 1 wei of Ether?
  • 1.14. What is the difference between assert and require?
  • 1.15. What is a flash loan?
  • 1.16. What is the check-effects-interaction pattern?
  • 1.17. What is the minimum amount of Ether required to run a solo staking node?
  • 1.18. What is the difference between fallback and receive?
  • 1.19. What is reentrancy?
  • 1.20. What prevents infinite loops from running forever?
  • 1.21. What is the difference between tx.origin and msg.sender?
  • 1.22. How do you send Ether to a contract that does not have payable functions, or a receive or fallback?
  • 1.23. What is the difference between view and pure?
  • 1.24. What is the difference between transferFrom and safeTransferFrom in ERC721?
  • 1.25. How can an ERC1155 token be made into a non-fungible token?
  • 1.26. What is an access control and why is it important?
  • 1.27 What does a modifier do?
  • 1.28. What is the largest value a uint256 can store?
Edit on GitHub
  1. Ethereum Dev
  2. Solidity Notes
  3. Interview Questions

1. Easy - Interview Questions

Last updated 6 months ago

1.1. What is the difference between private, internal, public, and external functions?

A private function is only accessible inside the contract in which it is defined. An internal function function is only accessible inside the contract in which it is defined AND inherited contracts. An external function is intended to be called from outside the contract in which it is defined but can be called by using this.<FUNCTION_NAME>(). It's used to reduce gas costs rather than to actually stop it from being called by the current contract. A public function is callable by anyone, anywhere.

1.2. Approximately, how large can a smart contract be?

Ethereum enforces a maximum contract size of 24 KB (24,576 bytes) for the bytecode of deployed contracts. This limit is meant to prevent overly large contracts from consuming excessive blockchain resources and ensure efficient validation and execution. Deploying a smart contract must fit within the block gas limit, which varies but is typically around 30 million gas on Ethereum mainnet.

E.g. A contract could have a deployed bytecode size of less than 24 KB but still use more than the block gas limit if it had complex logic in its constructor which is executed during deployment.

1.3. What is the difference between create and create2?

The CREATE opcode creates a contract at an address determined by the deployer nonce. So it is possible to know the address in advance but only if you know what the the deployer nonce will be at the time of deployment.

CREATE2 opcode allows contracts to be deployed at a specific address derived from:

  • The deployer’s address.

  • A salt value (a 32-byte arbitrary value provided by the deployer).

  • The keccak256 hash of the contract’s bytecode.

1.4. What major change with arithmetic happened with Solidity 0.8.0?

Over and underflow checks were added by default. The compiler now automatically reverts the transaction if an arithmetic operation results in an overflow or underflow. This enhancement makes contracts more secure by default and reduces the need for external libraries like SafeMath for these checks which were needed in previous versions.

1.5. What special CALL is required for proxies to work?

delegatecall() is used to preserve the context of a call, which is a requirement for proxy contracts.

1.6. How do you calculate the dollar cost of an Ethereum transaction?

Find the gas cost of the tx and multiply it by the price of Ethereum as the time of the tx.

1.7. What are the challenges of creating a random number on the blockchain?

A blockchain is inherently deterministic. To achieve consensus on the state of a blockchain, every node must be able to come to the same output for a given set of inputs. Therefore, true random number generation is not possible and external sources of randomness are required e.g. oracles.

1.8. What is the difference between a Dutch Auction and an English Auction?

A Dutch auction starts with a high price that decreases incrementally until a buyer accepts the current price, leading to a quicker sale at the first bid. In contrast, an English auction begins at a low starting price and increases with competitive bids until no higher offers are made, allowing bidders to actively compete for the highest price. The Dutch auction is faster and can prevent bidding wars, while the English auction encourages competition and transparency in price discovery.

1.9. What is the difference between transfer and transferFrom in ERC20?

In the ERC20 standard, transfer allows a token holder to send tokens directly to another address, reducing the balance of the sender and increasing the balance of the recipient. transferFrom facilitates token transfers on behalf of a third party, requiring prior approval via approve for the spender to move a specified number of tokens from the owner’s account. This makes transferFrom useful for use cases like escrow services or delegated transfers where a contract or user acts on behalf of another.

1.10. Which is better to use for an address allowlist: a mapping or an array?

Mapping. A mapping allows constant-time (O(1)) lookups and is much more efficient for regular checks like allowlists. If a user is on the allowlist, simply set their address value in the mapping to be true and it will be fast and gas efficient to check. To check if a user is in an array, the entire array may need to be processed, which means that the gas costs of interacting with the contract will grow exponentially with the size of the allow list array.

1.11. Why shouldn’t tx.origin be used for authentication?

If a contract uses tx.origin to authenticate an address then it is vulnerable to being manipulated by a malicious man-in-the-middle contract. If a malicious contract can pass through the tx.origin then it could call a function e.g. an NFT transfer, without the explicit consent of the owner. This is why msg.sender is more secure as the context is the address of the contract that directly called the function, unless delegatecall() has been used.

1.12. What hash function does Ethereum primarily use?

keccak256. This is a variant of the SHA-3 family but differs slightly from the finalized NIST standard version of SHA-3. The keccak256 function is used in various core aspects of Ethereum, such as generating addresses, creating unique identifiers, and verifying data integrity within smart contracts.

1.13. How much is 1 gwei of Ether? How much is 1 wei of Ether?

1 Gwei = 0.000000001 ETH

1 Wei = 0.000000000000000001 ETH

1.14. What is the difference between assert and require?

require is used to validate conditions that are expected to be true under normal circumstances, such as function input validation or checking contract state. It is typically used for user input, contract interaction conditions, and external calls. If the condition fails, require will revert the transaction and return any remaining gas to the caller. require can include a custom error message that is returned when the condition fails, making it easier to debug and understand why the transaction reverted.

assert is used to test for internal errors and invariants within the code that should never fail. It checks conditions that, if broken, indicate a bug in the contract. Unlike require, assert is used to validate assumptions that should always hold true in contract logic. If an assert statement fails, it consumes all the gas provided for the transaction. assert does not provide an error message, so debugging is more difficult. It is meant for cases where a failure indicates a severe bug.

1.15. What is a flash loan?

A flash loan is a function offered by lending platforms like Aave that allows anyone to borrow a huge amount of funds, at a fixed interest rate, for a single tx. The only condition is that the borrowed tokens + interest must be returned within the same tx it is borrowed, or the whole tx will revert. Flash loans are a powerful financial primitive not found in traditional financial markets and allow anyone to exploit financial opportunities, even when starting with almost no capital.

Anyone can be a whale for 12 seconds.

1.16. What is the check-effects-interaction pattern?

The check-effects-interaction pattern in Solidity enforces an order to prevent reentrancy vulnerabilities and unexpected outcomes. All checks and verifications should happen first, and then all effects that make changes to the state of the current smart contract should be actioned. Finally, only when those first two steps have been completed should the function interact with external contracts and/or users.

1.17. What is the minimum amount of Ether required to run a solo staking node?

32 ETH.

1.18. What is the difference between fallback and receive?

 /**
  * Explainer from: https://solidity-by-example.org/fallback
  * ETH is sent to contract
  *      is msg.data empty?
  *           /    \
  *         yes    no
  *         /       \
  *    receive()?  fallback()
  *      /     \
  *    yes     no
  *    /        \
  * receive()  fallback()
  */

1.19. What is reentrancy?

When an external call in a function allows for another function to be called before expected state changes have been made. E.g. A send funds function that sends ETH before updating a user's balance. When the ETH is sent, the call to that user could be to a contract, which would allow for its receive or fallback function to reenter the calling contract and trigger the sending function again.

1.20. What prevents infinite loops from running forever?

30 million gas block limit on Ethereum mainnet. Even on L2s with higher gas limits still would reach a limit that stops loops from running forever. A caller would also run out of ETH to pay for gas even before the gas limit is reached.

1.21. What is the difference between tx.origin and msg.sender?

tx.origin is the original source of the tx, the Externally Owned Account (EOA). msg.sender is the address of the direct caller of the current function, so in a chain of contract calls, only the final contract that calls the function would show as msg.sender.

1.22. How do you send Ether to a contract that does not have payable functions, or a receive or fallback?

selfdestruct() no longer deletes the code of a contract once deployed, but currently during deployment, if selfdestruct() is called it can be used to force sent ETH.

1.23. What is the difference between view and pure?

View functions can view the state of the blockchain. Pure functions cannot view any state and can only manipulate data passed to them.

1.24. What is the difference between transferFrom and safeTransferFrom in ERC721?

transferFrom transfers ownership of an NFT from one address to another without performing additional checks. It does not verify whether the recipient address is a contract or a regular address. If you use transferFrom to send an NFT to a smart contract that doesn’t handle ERC721 tokens, the token could be “stuck” since the contract might not have a way to process it.

safeTransferFrom ensures a safe transfer by performing an additional check when sending an NFT to a contract address. It calls onERC721Received on the recipient contract if it’s a contract, ensuring that the contract is aware of the incoming NFT and can handle it properly. If the recipient contract does not implement the required onERC721Received function, the transaction will revert, preventing the NFT from being “stuck” in a contract that can’t process it.

1.25. How can an ERC1155 token be made into a non-fungible token?

In the ERC1155 standard, tokens are inherently semi-fungible, meaning they can be fungible or non-fungible based on how they’re defined. To create a non-fungible token (NFT) within an ERC1155 contract, you can treat specific token IDs as unique, which gives them non-fungible properties.

1.26. What is an access control and why is it important?

Modifers are useful for standardizing ownership and role-based checks on functions. Common access controls are onlyOwner.

1.27 What does a modifier do?

A modifier in Solidity is a keyword that defines reusable code to be run either before or after a function’s main logic, depending on the placement of the _; statement within the modifier. Modifiers are flexible, allowing you to add functionality to functions in a modular, organized way.

1.28. What is the largest value a uint256 can store?

chisel

type(uint256).max

Type: uint256
├ Hex: 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
├ Hex (full word): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
└ Decimal: 115792089237316195423570985008687907853269984665640564039457584007913129639935

📝
❔
🟢
https://eth-converter.com
Over 150 interview questions for Ethereum Developers - RareSkillsRareSkills
Logo