# Writing a task

> The Scenario contract, the three condition templates, and how the arbiter runs a check.


A task is one Solidity file and one condition. The worker's job is to make the condition true. The arbiter decides, with no human judgement involved.

## The Scenario contract

Your file must contain a contract named `Scenario`. The arbiter deploys it on a fresh chain, sending it the HYPE you set in the form. Its constructor sets up the system the way it looks in real life: deploy your contracts, add other users' deposits, grant roles. Then `target()` tells the arbiter which contract to attack.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

contract Vault {
    mapping(address => uint256) public balanceOf;

    function deposit() external payable {
        balanceOf[msg.sender] += msg.value;
    }

    function withdraw() external {
        uint256 amount = balanceOf[msg.sender];
        require(amount > 0, "nothing to withdraw");
        (bool ok,) = msg.sender.call{value: amount}("");
        require(ok, "send failed");
        balanceOf[msg.sender] = 0;
    }
}

contract Scenario {
    Vault public immutable vault;

    constructor() payable {
        vault = new Vault();
        vault.deposit{value: msg.value}(); // other users' deposits
    }

    function target() external view returns (address) {
        return address(vault);
    }
}
```

Compiler versions: Solidity 0.8.24 and 0.7.6 are available to the arbiter. The arbiter picks the first one your `pragma` allows. Imports are not available: put everything in one file.

## Condition templates

You pick one template. Views are functions on the target with no arguments, written like `owner()`.

### Funds leave

The attacker ends with more of an asset than it started with.

| Asset | Measured as |
|---|---|
| HYPE | The attacker's HYPE balance |
| ERC-20 at an address | `balanceOf(attacker)` on that token |
| ERC-20 from a getter | The token address returned by a view on the target, for example `token()` |
| The target itself | The target is a token: `balanceOf(attacker)` on it |

### Role taken

A view on the target that names a privileged role, for example `owner()`, returns the attacker after the exploit. It must not already point at the attacker before.

### Invariant breaks

Two views on the target that return `uint256`, compared with `>=`, `<=` or `==`, for example `totalAssets() >= totalSupply()`. The rule must hold before the exploit and fail after it.

If the condition is already true before any exploit runs, the task itself is invalid and no one can be paid for it. **Check in browser** on the post form catches this before you seal.

## How the check runs

For every attempt the arbiter:

1. Compiles your source and the exploit together (solc 0.8.24 or 0.7.6, optimizer on, 200 runs).
2. Starts a fresh in-memory chain with chain id 99901, a fixed block number and timestamp, and no outside network.
3. Deploys `Scenario` from a deployer account with your HYPE, and reads `target()`.
4. Deploys `Exploit` from a separate attacker account and gives it 10 HYPE.
5. Reads the condition, calls `run(target)` once (up to 25 million gas), and reads it again.
6. Repeats steps 2 to 5 on a second fresh chain. Both runs must agree.

There are no cheat codes: the exploit can only do what a real contract can do.

## Tips for a good task

- **Make the scenario realistic.** Seed the deposits, balances and roles a real attacker would find.
- **Pick the narrowest condition** that captures the failure you fear. "Funds leave" is the most common.
- **Keep bounties small.** The escrow contract is unaudited, so tasks are capped at 50 USDC.
- **Give enough attempts.** Workers often need two or three tries on a real system.

> **Later** Deployed contracts, checked on a fork of Elysium at a pinned block, come after the pilot together with an owner signature that proves you may test them.
