Docs / Writing a task

Writing a task

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

View as Markdown

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 ETH 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.

// 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. Use one of them in your pragma.

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
ETH The attacker's ETH 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 this before you post.

How the check runs

For every attempt the arbiter:

  1. Compiles your source and the exploit together (Foundry's forge build).
  2. Starts a fresh local chain with chain id 4663 and a fixed timestamp.
  3. Deploys Scenario from a deployer account with your ETH, and reads target().
  4. Deploys Exploit from a separate attacker account and gives it 10 ETH.
  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. The arbiter has no outside network during a check.

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.
  • Use test values. In the pilot the arbiter is simulated; do not paste a production contract.
  • Give enough attempts. Workers often need two or three tries on a real system.

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