# Breach conditions

A breach condition is the Owner's definition of "broken", written and sealed before any Breaker starts. The Warden does not judge severity or intent: it reads on-chain state before and after the exploit and applies the condition mechanically. This page gives the exact semantics of the three templates and the environment every run uses.

## The Scenario contract

Every Sanctum contains a `contract Scenario`. Its constructor is `payable` and receives `scenarioEth`, the ETH amount the Owner sets in the terms. It deploys and funds the contract under test, and exposes it through a view:

```solidity
function target() external view returns (address);
```

Conditions are read against `target()`. The Scenario may not import any file.

## Who counts as the attacker

The attacker is **the Exploit contract and a fresh attacker account (EOA), taken together**. The EOA's key is random for every run. Both start with 10 ETH: the EOA is funded before it deploys the Exploit, and the Exploit contract is funded right after deployment. Gas price on the Warden chain is 0, so gas never changes a balance.

## The three templates

### Funds drained

```json
{ "type": "funds-drained", "asset": "eth" }
```

Breached when the attacker's combined holdings of the asset (Exploit balance + EOA balance) are **higher after** `run(target)` than before.

| `asset` | What is measured |
|---|---|
| `"eth"` | Native ETH balance |
| `"target"` | The target itself is an ERC-20; its `balanceOf` |
| `"0x…"` | The ERC-20 at that address |
| `"token()"` (any no-argument getter) | The ERC-20 whose address the target returns from that view |

The asset token must have code, or the task is invalid.

### Control seized

```json
{ "type": "control-seized", "view": "owner()" }
```

Breached when the named no-argument view on the target returns the Exploit contract **or** the attacker EOA after the run, and returned neither before it.

### Rule broken

```json
{ "type": "rule-broken", "left": "totalSupply()", "op": "<=", "right": "cap()" }
```

The rule `left op right` must **hold before** the run and **fail after** it.

- `op` is one of `>=`, `<=`, `==`.
- Each side is a no-argument view returning `uint256` (for example `totalDeposits()`), `@balance` (the target's ETH balance), or a decimal integer such as `1000`.

## Outcomes

| Outcome | When |
|---|---|
| **BREACHED** | Both independent runs succeed and both meet the condition. |
| **HELD** | Anything else on the Breaker's side: the condition is not met, `run()` reverts, the Exploit fails to compile or deploy, a run times out, or the two runs disagree. |
| **INVALID_TASK** | The task itself cannot be checked fairly: the Scenario fails to compile or deploy, `target()` fails or has no code, the condition cannot be read before the exploit, or the condition is **already true before** the exploit runs. |

Only BREACHED can release a bounty. The escrow cannot pay on a HELD verdict because the signed outcome is part of the digest it checks.

## The run environment

Each run starts a new, empty local chain. Nothing is forked and nothing is shared between the two runs.

| Setting | Value |
|---|---|
| Chain | fresh anvil, chain id 4663, no fork |
| Hardfork | cancun |
| EVM target | `cancun` for 0.8.24, `istanbul` for 0.7.6 |
| Block gas limit | 30,000,000 |
| Genesis timestamp | 1798761600 (2027-01-01 00:00 UTC); each transaction advances one second |
| Gas for `run()` | 25,000,000 |
| Gas price / base fee | 0 |
| Build time limit | 120 s |
| Time limit per run | 60 s |
| Compilers | `0.8.24`, `0.7.6` |

The order inside each run: deploy Scenario (with `scenarioEth`) from a random deployer, read `target()`, deploy Exploit from the attacker EOA, fund both with 10 ETH, read the condition, call `run(target)`, read the condition again.

## Worked examples [ EXAMPLE ]

These are the public Yard samples in `warden/samples/`. Each is BREACHED by its reference exploit and HELD against its patched version.

### Funds drained · Tide Vault [ EXAMPLE ]

A vault holding 10 ETH sends ETH before zeroing the caller's balance.

```json
{ "type": "funds-drained", "asset": "eth" }
```

```solidity
function withdraw() external {
    uint256 amount = balances[msg.sender];
    require(amount > 0, "empty balance");
    (bool ok, ) = msg.sender.call{value: amount}("");
    require(ok, "payout failed");
    balances[msg.sender] = 0;
}
```

The exploit deposits 1 ETH, calls `withdraw()`, and re-enters from `receive()` while the vault still holds at least 1 ETH. The attacker ends with more ETH than it started with.

### Control seized · Fee Treasury [ EXAMPLE ]

A 0.7.6 treasury whose `initialize()` can be called again by anyone.

```json
{ "type": "control-seized", "view": "owner()" }
```

```solidity
contract Exploit {
    function run(address target) external {
        ITreasury(target).initialize(address(this), 0);
    }
}
```

Before the run, `owner()` is the Scenario. After it, `owner()` is the Exploit contract.

### Rule broken · Capped Points [ EXAMPLE ]

A points token promises `totalSupply <= cap` (cap 1000, 900 pre-minted), but its faucet checks the cap for one drip of 100 while minting `n` drips.

```json
{ "type": "rule-broken", "left": "totalSupply()", "op": "<=", "right": "cap()" }
```

```solidity
contract Exploit {
    function run(address target) external {
        IPoints(target).claim(3);
    }
}
```

Before: 900 ≤ 1000 holds. After: 1200 ≤ 1000 fails.

## Writing a good condition

- Make sure it is **false before** any exploit, or every attempt returns INVALID_TASK.
- Fund the Scenario with enough `scenarioEth` for the loss you care about.
- Prefer a rule that captures the invariant you promise users (`totalAssets() >= totalShares()`, `@balance >= totalDeposits()`) over a narrow symptom.
