Solidity Solidity DeFi and Token Standards 1 — Questions and Answers
Question 1: What is the ERC-20 `allowance` mechanism and what attack does it enable?
- It lets owners approve spenders to transfer tokens, but a race condition allows double-spending if approval amount is changed (Correct answer)
- It prevents token transfers above a daily limit
- It is a blacklist mechanism to block specific addresses
- It enables the contract to burn tokens automatically
Correct answer: It lets owners approve spenders to transfer tokens, but a race condition allows double-spending if approval amount is changed
The ERC-20 approve/transferFrom pattern has a race condition: if a spender acts between an owner reducing allowance from N to M, they can spend N+M tokens total.
Question 2: What does the ERC-777 standard add over ERC-20?
- Hooks that notify sender and recipient contracts on every transfer, enabling richer interactions without separate approve+transferFrom calls (Correct answer)
- On-chain governance for token parameter changes
- Native DEX integration without a router contract
- Cross-chain transfer capabilities via bridge hooks
Correct answer: Hooks that notify sender and recipient contracts on every transfer, enabling richer interactions without separate approve+transferFrom calls
ERC-777 adds `tokensToSend` and `tokensReceived` hooks called on registered operator and recipient contracts, enabling automatic reactions to transfers.
Question 3: What is a 'rebasing token' in DeFi and what challenge does it pose for Solidity integrations?
- A token whose total supply and all balances adjust periodically, causing balance reads to return different values without transfer events (Correct answer)
- A token that automatically compounds staking rewards every block
- A token that resets its price to $1 on every rebase
- A token that requires re-approval on every use
Correct answer: A token whose total supply and all balances adjust periodically, causing balance reads to return different values without transfer events
Rebasing tokens like AMPL adjust all account balances proportionally when supply changes, breaking protocols that cache balance snapshots between transactions.
Question 4: What is the ERC-4626 Tokenized Vault Standard used for?
- Standardizing yield-bearing vaults with a common deposit/withdraw/shares interface (Correct answer)
- Creating non-fungible tokens for vault ownership certificates
- Defining a standard for on-chain order books
- Standardizing cross-chain asset bridges
Correct answer: Standardizing yield-bearing vaults with a common deposit/withdraw/shares interface
ERC-4626 defines a standard interface for yield vaults (deposit assets, receive shares, redeem shares for assets), enabling composable integration across DeFi protocols.
Question 5: What is 'slippage tolerance' in Solidity DEX contracts and how is it enforced?
- A minimum output amount parameter in swap functions that reverts the transaction if the actual output is less than expected (Correct answer)
- The maximum gas price allowed before a swap reverts
- A percentage fee deducted by the router before execution
- The block delay allowed between swap quote and execution
Correct answer: A minimum output amount parameter in swap functions that reverts the transaction if the actual output is less than expected
DEX routers accept a `amountOutMin` parameter; if the actual amount received (after fees and price movement) is less, the transaction reverts, protecting users from excessive slippage.
Question 6: What is 'impermanent loss' in the context of Automated Market Maker (AMM) liquidity provision?
- The loss LPs experience relative to holding tokens when token prices diverge from the deposit ratio (Correct answer)
- Transaction fees lost due to failed or reverted swaps
- Gas costs that cannot be recovered from a liquidity position
- Slippage costs incurred when adding large liquidity positions
Correct answer: The loss LPs experience relative to holding tokens when token prices diverge from the deposit ratio
When prices change from deposit time, arbitrageurs rebalance the pool, causing LPs to hold more of the depreciating token — the difference from just holding is impermanent loss.
What is the ERC-20 `allowance` mechanism and what attack does it enable?