DeFi engineer interview questions and how to answer them
DeFi engineer interview questions go past Solidity syntax into how money moves through a protocol: automated market maker math, lending and liquidations, price oracles, rounding and fixed-point precision, and the economic attacks that flash loans make cheap. Expect a protocol-flavored coding task or a code review of a vault or pool, plus a design discussion where you defend your parameters. The candidates who do well reason about incentives and worst cases as carefully as about code.
By Evin JohnPublished 9 min read
What a DeFi engineer builds
A DeFi engineer designs and ships the contracts behind exchanges, lending markets, stablecoins, yield vaults, derivatives and staking systems, along with the off-chain pieces that keep them healthy: keepers that trigger liquidations, bots that rebalance, indexers and risk dashboards. The work mixes three skills. You write and test smart contracts, you reason about the protocol as a market where every participant follows their own incentives, and you plan for the day someone with a large flash loan tries to bend your assumptions. For the general smart contract side of hiring, such as gas, storage layout and proxy upgrades, see the blockchain developer interview questions; this page assumes that ground and goes deeper into protocol design.
- Numeracy: you can work through a swap, an interest accrual or a liquidation on paper.
- Adversarial thinking: you ask who profits if a price moves, a block is reordered or a token behaves strangely.
- Precision habits: you know which way every division rounds and who that favors.
- Composability awareness: your protocol will be called by contracts you have never seen, and it will call others.
How DeFi interviews are usually structured
- Intro callYour background, protocols you have shipped or audited, and which parts of DeFi you know best. Teams are often small and remote.
- Technical screenSolidity and EVM questions, then mechanism questions such as how a constant-product pool prices a trade.
- Take-home or live buildA small vault, staking pool, auction or lending market, often in Foundry, judged on tests as much as on code.
- Security reviewYou read a protocol snippet with a planted economic bug and explain the attack and the fix.
- Design discussion and team roundsParameters, failure modes and trade-offs for a feature, then how you work with auditors, researchers and the community.
AMM and exchange questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| How does a constant-product pool price a swap? | Core AMM math | Reserves x and y keep x times y at least constant after fees, so the output for a given input follows from that curve |
| Why does a large trade get a worse average price? | Price impact | Each unit bought moves along the curve; impact grows with trade size relative to reserves |
| What is slippage protection, and who sets it? | User safety | A minimum output and a deadline chosen by the caller, enforced by the router so a reordered trade reverts |
| Explain impermanent loss. | LP economics | A liquidity provider ends with less value than holding the two tokens when the price moves; with a 50/50 constant-product pool, a doubling in price costs about 5.7% against holding, before fees |
| What does concentrated liquidity change? | Newer designs | Providers choose a price range, as in Uniswap v3-style pools, which deepens liquidity near the price but adds range management and more complex accounting |
| How does a sandwich attack work? | MEV | An attacker buys before a victim's trade and sells after it; tight slippage limits and private order flow reduce the damage |
| Why can't a protocol use the pool's spot price as an oracle? | Oracle safety | Spot price can be moved within one transaction, often with borrowed funds, so it says nothing reliable about fair value |
def amount_out(amount_in, reserve_in, reserve_out, fee_bps=30):
"""Constant-product swap: x * y stays >= k after the fee is taken."""
if amount_in <= 0 or reserve_in <= 0 or reserve_out <= 0:
raise ValueError("amounts and reserves must be positive")
in_after_fee = amount_in * (10_000 - fee_bps)
numerator = in_after_fee * reserve_out
denominator = reserve_in * 10_000 + in_after_fee
return numerator // denominator # round down: the pool never pays out extra
# A pool with 1,000 token A and 2,000 token B (spot price 2 B per A)
x, y = 1_000 * 10**18, 2_000 * 10**18
for trade in (1, 10, 100):
out = amount_out(trade * 10**18, x, y)
print(f"sell {trade:>3} A -> {out / 10**18:.4f} B, "
f"avg price {out / (trade * 10**18):.4f}")
assert (x + trade * 10**18) * (y - out) >= x * y # k never shrinks
# sell 1 A -> 1.9920 B, avg price 1.9920
# sell 10 A -> 19.7432 B, avg price 1.9743
# sell 100 A -> 181.3222 B, avg price 1.8132Interviewers like this example because it covers three habits at once: integer math with token decimals, a fee applied before the curve, and rounding that protects the pool. Expect a follow-up such as "what breaks if the division rounds up?" (the pool can pay out slightly more than the curve allows, and repeated tiny swaps can drain value).
Lending and liquidation questions
- Why are DeFi loans overcollateralized? There is no credit check or legal recourse, so the protocol holds more collateral than the debt and sells it if the buffer gets thin.
- What is a health factor? Collateral value times its liquidation threshold, divided by debt. Lending protocols such as Aave use the term; below 1 the position can be liquidated.
- Who liquidates, and why would they bother? Anyone, usually bots, paid by a liquidation bonus. Too small a bonus and nobody acts in a crash; too large and borrowers lose more than needed.
- How does a utilization-based interest rate model work? Rates rise gently as more of the pool is borrowed, then steeply past a target utilization so lenders can always withdraw.
- What is bad debt, and how does it happen? Debt larger than its collateral, usually after a price gap, an oracle delay or illiquid collateral. Good answers mention reserves, caps and who absorbs the loss.
- How would you list a new, thinly traded token as collateral? Low loan-to-value, supply and borrow caps, an isolated market and a robust price source, or not at all.
- What can go wrong with a partial liquidation design? Dust positions too small to be worth liquidating, and rounding that leaves debt behind.
def health_factor(collateral_value, liq_threshold, debt_value):
"""Above 1 the position is safe; at or below 1 it can be liquidated."""
if debt_value == 0:
return float("inf")
return collateral_value * liq_threshold / debt_value
# 10 units of collateral priced at 1,500 each, 80% threshold, 9,000 borrowed
print(round(health_factor(10 * 1500, 0.80, 9000), 3)) # 1.333
# price drop at which the position becomes liquidatable
print(9000 / (10 * 0.80)) # 1125.0
print(round(health_factor(10 * 1125, 0.80, 9000), 3)) # 1.0Oracle and economic attack questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What is a flash loan, and why does it change threat models? | Attack cost | A loan borrowed and repaid in one transaction, so an attacker can use huge capital for the price of a fee and gas |
| How do you choose a price oracle? | Oracle design | A decentralized feed or a time-weighted average, checks on staleness and sanity bounds, and a fallback plan when the feed stops |
| How would someone manipulate a TWAP oracle? | Deeper oracle risk | Holding a moved price across blocks, which costs more in thin pools and short windows; longer windows trade safety for lag |
| What is the first-depositor or share inflation attack on a vault? | ERC-4626 vaults | An attacker mints a tiny share then donates assets so later deposits round down to zero shares; fixes include virtual shares, a seed deposit or minimum shares |
| What is read-only reentrancy? | Composability bugs | Another protocol reads your view function mid-update and gets an inconsistent price; guard views or document the risk |
| Which token behaviors break naive accounting? | Token integration | Fee-on-transfer, rebasing, missing return values, different decimals and blocklists; measure balances before and after transfers |
| How can governance itself be attacked? | Governance risk | Borrowed voting power, rushed proposals and malicious upgrades; snapshots of voting power, quorums and timelocks help |
Precision and fixed-point math questions
- Why does DeFi math use fixed-point numbers? The EVM has no floats, so values are scaled integers, often by 10^18 (sometimes called WAD) or 10^27 (RAY) for rates.
- Which way should a division round? Against the user and in the protocol's favor: round shares minted down and shares burned up, debt up and collateral credit down.
- How do you multiply two large numbers then divide without overflow? A full-precision mulDiv helper, or reorder the math with care about precision loss.
- How do you handle a 6-decimal token and an 18-decimal token in one pool? Normalize to a common scale internally and convert only at the edges.
- How does interest accrue without looping over every borrower? A global index that grows each block or second, with each position storing the index at its last update.
MEV, testing and operations questions
- What is MEV, and how can a protocol reduce the harm to users? Value extracted by reordering or inserting transactions. Slippage limits, deadlines, batch auctions, commit-reveal and private submission paths each help in different cases.
- How do you fuzz and invariant-test a protocol? State properties that must always hold, such as total shares backed by assets or no position below its threshold after a valid action, then let a fuzzer hunt for sequences that break them, for example with Foundry or Echidna.
- Why run fork tests? To test against real deployed tokens, pools and oracles, including their odd behaviors.
- What do you set up before mainnet launch? Audits, a bug bounty, caps for the early period, monitoring and alerts, a pause role with clear limits, and timelocks on admin actions.
- When should a protocol be pausable, and by whom? When a fast stop limits damage, held by a multisig with a narrow scope, and never in a way that traps user withdrawals forever.
- Tell me about an exploit you studied closely. Pick a public post-mortem, explain the root cause in two sentences and what design rule you took from it. Do not guess at numbers you cannot check.
Behavioral and team questions
- Describe a time you pushed back on a launch date because the protocol was not ready.
- How do you explain a risk parameter change to a community that votes on it?
- Tell me about an audit finding you disagreed with and how you resolved it.
- How do you stay current without chasing every new protocol design?
Fictional example
- I'd start from the job the bonus does: it has to pay a liquidator enough to act during a fast drop, after gas and the slippage of selling the collateral on-chain. So I'd look at how deep the available liquidity is for that token and how far its price has moved in a short window historically. A thin token needs a bigger bonus, but a bigger bonus also means borrowers lose more, so I'd pair it with a lower loan-to-value and a supply cap at launch. Then I'd simulate a few crash paths with our liquidation bot against a fork, check that positions close before they go underwater, and propose the numbers with that evidence so governance can see the trade-off.
Two-week study plan
- Days 1-3: AMMsImplement a constant-product pool with fees and slippage checks, then read how concentrated liquidity tracks ranges.
- Days 4-6: LendingBuild a tiny lending market with an interest index, a health factor and liquidations. Break it with a price drop in a test.
- Days 7-9: AttacksWrite a test that performs an oracle manipulation and a vault inflation attack against your own code, then fix both.
- Days 10-12: InvariantsAdd invariant tests to everything you built and run a fuzzer until it stops finding bugs.
- Days 13-14: Talk it throughPractice explaining one design choice and one exploit post-mortem out loud in five minutes each.
Mechanism questions reward clear spoken reasoning, which is hard to judge from your own head. In practice sessions, Natively, an AI interview assistant for Mac and Windows, transcribes the mock interview so you can reread how you explained a liquidation path, and it can read a contract snippet or pool math problem from a screenshot and talk through an approach with code. The transcript and notes stay in meeting history, which makes it easy to spot the step you skipped in a security review drill.
Questions people ask
What questions are asked in a DeFi engineer interview?
Expect constant-product AMM math, slippage and impermanent loss, lending health factors and liquidations, oracle design and flash loan attacks, vault share rounding, fixed-point precision, MEV and how you test a protocol with fuzzing and invariants.
How is a DeFi engineer interview different from a blockchain developer interview?
Both test Solidity and the EVM, but DeFi interviews spend more time on protocol mechanics and economic security: how prices, interest and liquidations work and how an attacker with borrowed capital could profit.
Is there a coding task in a DeFi interview?
Often. Common tasks are a small vault, staking pool, auction or lending market with tests, or a review of protocol code with a planted bug that you must explain and fix.
How should I prepare for a DeFi engineering interview?
Build a tiny AMM and lending market, attack them in tests with oracle manipulation and vault inflation, add invariant tests, and practice explaining one design trade-off and one public exploit post-mortem out loud.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
