Skip to content

Reading list

Learn Smart contracts from real reports

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

12 reports, easiest first.

  1. Super pool uses `ERC20.approve` instead of safe approvals, causing it to always revert on some ERC20s

    Sentiment V2 Beginner

    The SuperPoolFactory and SuperPool contracts use ERC20.approve, which expects a boolean return value, but some ERC20 tokens like USDT do not return a value, causing the transaction to revert. This prevents the creation and use of super pools for those assets.

    Some tokens, like USDT, behave slightly differently from the standard: when you call approve, they don't send back a yes/no answer. The code here expects that answer, so it crashes and the whole action fails. This means you can't create a super pool for those tokens.

    The lesson. The code calls IERC20.approve directly, which assumes the token returns a boolean, but some tokens (e.g., USDT) do not return a value, causing a revert.

  2. _onTransferReceived() does not work as intended

    Superposition Beginner

    The contract's transfer callback check uses an inverted comparison, so it reverts when a compliant receiver returns the expected selector and accepts when the selector is wrong. This prevents safe transfers to contracts that correctly implement the ERC-721 receiver interface.

    When an NFT is sent to a contract, the sending contract asks the receiving contract to confirm it can handle NFTs by calling a special function. The receiving contract is supposed to reply with a specific code word. This code checks for the wrong answer: it rejects the correct code word and accepts anything else, so well-behaved receiving contracts cannot accept the NFT.

    The lesson. The require statement uses '!=' instead of '==' when comparing the returned selector to the expected ERC-721 receiver selector.

  3. Anyone can reset fees to 0 value when Vault is deployed

    Popcorn contest Beginner

    The changeFees function in the Vault contract does not check whether a fee change was actually proposed, so anyone can call it after the quit period and set fees to zero. This stops the protocol from collecting fees.

    A smart contract is a program on a blockchain. This vault contract lets someone change fees, but it forgot to check that a fee change was actually proposed first. Because of that, anyone can call the change function and set all fees to zero, so the protocol stops earning money.

    The lesson. The changeFees function lacks a check that proposedFeeTime is non-zero, allowing it to be called before any fee change is proposed.

  4. Calling swapAVAXForExactTokens function while sending excess amount cannot refund such excess amount

    Trader Joe v2 contest Beginner

    The swapAVAXForExactTokens function is supposed to refund any excess AVAX sent, but the refund calculation subtracts the sent amount from the required amount, causing an underflow revert whenever more than the required amount is sent. An attacker could not exploit this for gain, but ordinary users sending extra AVAX would have their transactions fail.

    When you call a function that swaps one cryptocurrency for another, you might send a bit more than needed, expecting the extra to be returned. Here, the code that returns the extra does the subtraction in the wrong order, so it tries to subtract a larger number from a smaller one. That causes the whole transaction to fail, so you lose nothing but the swap never happens.

  5. Tokens can be stuck forever in UniswapLiquidator because function retrieveTokens always reverts for USDT and all tokens that have transfer function that do not return boolean

    Anvil Beginner

    The retrieveTokens function in UniswapLiquidator calls IERC20.transfer, which expects a boolean return value, but tokens like USDT do not return a value, so the call always reverts. As a result, USDT sent to the contract becomes permanently frozen and cannot be recovered by the owner.

    Some tokens, like USDT, have a transfer function that does not return a true/false value, unlike the standard token interface. The contract's rescue function expects that return value, so when it tries to move USDT it fails and the tokens stay stuck forever.

    The lesson. The contract uses the standard IERC20 interface, which requires transfer to return a boolean, but some tokens (e.g., USDT) do not return a value, causing the call to revert.

  6. Missing Return Statement in _getReserves Function in MagicLpAggregator Contract

    Abracadabra Mimswap Beginner

    The _getReserves function in the MagicLpAggregator contract did not return the reserve values fetched from the pair contract, causing latestAnswer to always return zero. This could lead dependent systems to receive incorrect price data, potentially causing financial loss or system failure.

    A smart contract function was supposed to fetch two numbers (reserves) from another contract and pass them back, but it forgot to actually return them. So whenever the price function asked for those numbers, it got zero instead. Any system relying on that price would see a price of zero, which could cause serious problems.

    The lesson. The _getReserves function declared return values but did not return them, so the caller received default zero values.

  7. Incorrect emit due to wrong ordering of wethbalancebefore calculation

    Alchemix V3 Beginner

    In the strategy's deallocation function, the WETH balance before withdrawal is read after the withdrawal call, so the redeemed amount always computes to zero. This causes a false loss event to be emitted even when no loss occurred.

    A smart contract strategy moves money in and out of a vault. When taking money out, it tries to check how much actually came back by comparing the balance before and after. But it reads the 'before' balance too late, so both readings are the same and the difference is always zero, making it look like a loss happened.

    The lesson. The balance snapshot intended to represent the pre-withdrawal state is taken after the withdrawal, so the before and after values are identical.

  8. Missing totalSupply reduction in burnFrom allows supply manipulation (ERC20 Violation)

    Virtuals Protocol Beginner

    The burnFrom function in the FERC20 contract reduces a user's balance and emits a burn event but does not reduce the total supply. This allows the owner to manipulate the reported total supply, affecting market cap calculations and DeFi protocols that rely on it.

    In a standard token, burning tokens should reduce both the user's balance and the total number of tokens in existence. Here, the burn only reduces the user's balance, so the total supply stays the same, making the token appear more valuable than it is.

    The lesson. The burnFrom function does not update the _totalSupply variable when burning tokens.

  9. Unchecked transfers

    Boot Finance contest Beginner

    The smart contracts call ERC20 transfer and transferFrom without checking the returned boolean, so for tokens that return false instead of reverting on failure, airdrop participants could lose their tokens. The report recommends using SafeERC20 to handle non-standard tokens.

    Some tokens don't stop with an error when a transfer fails; they just return false. If the code ignores that false, it thinks the transfer worked when it didn't, so users might not get their tokens. This report points out places where the code ignores the result.

  10. Gettotaldeposited doesn t reflect the correct total deposited

    Alchemix V3 Beginner

    The getTotalDeposited function returns the contract's token balance instead of the tracked deposited shares, so a direct token transfer inflates the reported total. An attacker could send tokens directly to the contract to make the reported total deposited incorrect.

    A smart contract keeps a record of how many tokens users have deposited. The function that reports the total deposited should use that record, but instead it checks the contract's current token balance. If someone sends tokens directly to the contract, the balance goes up and the reported total becomes wrong.

    The lesson. Likely the function reads the contract's token balance instead of the internal accounting variable that tracks deposits.

  11. decrPosition09293696 will not work due to incorrect function signature

    Superposition Beginner

    The Solidity wrapper function decrPosition09293696 is missing the pool address parameter that the underlying Rust function requires, so any call to it will fail. This makes the decrease position functionality inaccessible through the wrapper.

    This is a smart contract bug where two parts of the system expect different inputs. The Solidity function that users call does not include the pool address, but the Rust function it calls requires it. So when someone tries to decrease their position, the call fails because the inputs do not match.

    The lesson. The Solidity function signature is missing the pool address parameter that the Rust function expects, causing a mismatch.

  12. MintableIncentivizedERC721 and NToken do not comply with ERC721, breaking composability

    ParaSpace contest Beginner

    The contract's supportsInterface function only reports support for the ERC721Enumerable and ERC721Metadata extensions, not for the base ERC721 interface. As a result, contracts that check for ERC721 compliance will not interoperate with these tokens, so marketplaces and other NFT facilities will not operate with them.

    ERC721 is a standard for non-fungible tokens (NFTs) on Ethereum. It includes a function called supportsInterface that lets other contracts ask 'do you follow this standard?' The contract in this report answers 'no' when asked if it follows the basic ERC721 standard, even though it implements the required functions. Because of that, other contracts that check for compliance will refuse to work with it.

    The lesson. The supportsInterface function returns true only for the ERC721Enumerable and ERC721Metadata interface IDs, omitting the base ERC721 interface ID.