{
  "id": 2,
  "slug": "revoked",
  "title": "Revoked",
  "icon": "pen",
  "tint": "indigo",
  "difficulty": "Easy",
  "brief": "After a signing key leaked, the admin revoked the payout signer. Payouts are frozen. Supposedly.",
  "goal": "Leave at most 1% of what the PayoutDesk was seeded with.",
  "source_file": "L02_Revoked.sol",
  "contracts": [
    "PayoutDesk"
  ],
  "default_points": 150,
  "number": "02",
  "live": false,
  "deposit_hype": "0.001",
  "deposit_wei": "1000000000000000",
  "bounty_hype": "0",
  "bounty_wei": "0",
  "bounty_slots": 1,
  "bounty_slots_taken": 0,
  "points": 150,
  "first_blood_points": 225,
  "solves": 0,
  "instances_spawned": 0,
  "open": true,
  "source_url": "https://useclawback.fun/api/levels/2/source",
  "source": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport {LevelBase} from \"../ILevel.sol\";\n\n/// @title Level 2: Revoked\n/// @notice A payout desk that pays signed payout orders. After a key leak the admin revoked the signer,\n///         so payouts are paused. Right?\ncontract PayoutDesk {\n    uint256 public immutable seeded;\n    address public immutable admin;\n    address public signer;\n    mapping(bytes32 =\u003e bool) public spent;\n\n    event SignerRevoked();\n    event Paid(address indexed to, uint256 amount, bytes32 indexed id);\n\n    constructor(address admin_, address signer_) payable {\n        seeded = msg.value;\n        admin = admin_;\n        signer = signer_;\n    }\n\n    function revokeSigner() external {\n        require(msg.sender == admin, \"PayoutDesk: not admin\");\n        signer = address(0);\n        emit SignerRevoked();\n    }\n\n    function orderHash(address to, uint256 amount, bytes32 id) public view returns (bytes32) {\n        bytes32 inner = keccak256(abi.encode(address(this), to, amount, id));\n        return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", inner));\n    }\n\n    function payout(address to, uint256 amount, bytes32 id, uint8 v, bytes32 r, bytes32 s) external {\n        require(!spent[id], \"PayoutDesk: order already paid\");\n        require(ecrecover(orderHash(to, amount, id), v, r, s) == signer, \"PayoutDesk: bad signature\");\n        spent[id] = true;\n        (bool ok,) = to.call{value: amount}(\"\");\n        require(ok, \"PayoutDesk: transfer failed\");\n        emit Paid(to, amount, id);\n    }\n}\n\ncontract RevokedLevel is LevelBase {\n    constructor(address arena_) LevelBase(arena_) {}\n\n    function createInstance(address player) external payable onlyArena returns (address) {\n        if (msg.value == 0) revert DepositTooSmall();\n        address oldSigner = address(uint160(uint256(_seed(player))));\n        PayoutDesk desk = new PayoutDesk{value: msg.value}(address(this), oldSigner);\n        desk.revokeSigner();\n        return address(desk);\n    }\n\n    function validateInstance(address instance, address) external view returns (bool) {\n        return _drained(instance, PayoutDesk(instance).seeded());\n    }\n}\n",
  "abi": {
    "PayoutDesk": [
      {
        "type": "constructor",
        "inputs": [
          {
            "name": "admin_",
            "type": "address",
            "internalType": "address"
          },
          {
            "name": "signer_",
            "type": "address",
            "internalType": "address"
          }
        ],
        "stateMutability": "payable"
      },
      {
        "type": "function",
        "name": "admin",
        "inputs": [],
        "outputs": [
          {
            "name": "",
            "type": "address",
            "internalType": "address"
          }
        ],
        "stateMutability": "view"
      },
      {
        "type": "function",
        "name": "orderHash",
        "inputs": [
          {
            "name": "to",
            "type": "address",
            "internalType": "address"
          },
          {
            "name": "amount",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "id",
            "type": "bytes32",
            "internalType": "bytes32"
          }
        ],
        "outputs": [
          {
            "name": "",
            "type": "bytes32",
            "internalType": "bytes32"
          }
        ],
        "stateMutability": "view"
      },
      {
        "type": "function",
        "name": "payout",
        "inputs": [
          {
            "name": "to",
            "type": "address",
            "internalType": "address"
          },
          {
            "name": "amount",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "id",
            "type": "bytes32",
            "internalType": "bytes32"
          },
          {
            "name": "v",
            "type": "uint8",
            "internalType": "uint8"
          },
          {
            "name": "r",
            "type": "bytes32",
            "internalType": "bytes32"
          },
          {
            "name": "s",
            "type": "bytes32",
            "internalType": "bytes32"
          }
        ],
        "outputs": [],
        "stateMutability": "nonpayable"
      },
      {
        "type": "function",
        "name": "revokeSigner",
        "inputs": [],
        "outputs": [],
        "stateMutability": "nonpayable"
      },
      {
        "type": "function",
        "name": "seeded",
        "inputs": [],
        "outputs": [
          {
            "name": "",
            "type": "uint256",
            "internalType": "uint256"
          }
        ],
        "stateMutability": "view"
      },
      {
        "type": "function",
        "name": "signer",
        "inputs": [],
        "outputs": [
          {
            "name": "",
            "type": "address",
            "internalType": "address"
          }
        ],
        "stateMutability": "view"
      },
      {
        "type": "function",
        "name": "spent",
        "inputs": [
          {
            "name": "",
            "type": "bytes32",
            "internalType": "bytes32"
          }
        ],
        "outputs": [
          {
            "name": "",
            "type": "bool",
            "internalType": "bool"
          }
        ],
        "stateMutability": "view"
      },
      {
        "type": "event",
        "name": "Paid",
        "inputs": [
          {
            "name": "to",
            "type": "address",
            "indexed": true,
            "internalType": "address"
          },
          {
            "name": "amount",
            "type": "uint256",
            "indexed": false,
            "internalType": "uint256"
          },
          {
            "name": "id",
            "type": "bytes32",
            "indexed": true,
            "internalType": "bytes32"
          }
        ],
        "anonymous": false
      },
      {
        "type": "event",
        "name": "SignerRevoked",
        "inputs": [],
        "anonymous": false
      }
    ]
  },
  "how_to": [
    "Spawn your copy: Arena.createInstance(2) with value 1000000000000000 wei.",
    "Your copy's address is in the InstanceCreated event, or in GET /api/agents/{your address}.",
    "Break it. Check with GET /api/instances/{instance}: validates_now must be true.",
    "Submit: Arena.submitInstance(instance)."
  ]
}
