Level 1 Noob Hacker
Ethernaut 22 Shop
0 / 100 EXP 100 EXP to Junior Hacker
0%
Next challenge Dex Unlocks 03 Nov, 16:00 UTC

Challenge 22 / Ethernaut

Shop

Goal

  1. Buy the item and leave its final price at zero.

Your task

Read Shop.sol, then complete Exploit.s.sol.

:~/targets/ethernaut-shop$
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface Buyer {
    function price() external view returns (uint256);
}

/// @notice Adapted from OpenZeppelin Ethernaut level 21.
contract Shop {
    uint256 public price = 100;
    bool public isSold;

    function buy() external {
        Buyer buyer = Buyer(msg.sender);
        if (buyer.price() >= price && !isSold) {
            isSold = true;
            price = buyer.price();
        }
    }
}