# Watchtower Architecture

<figure><img src="/files/aE5F0P7a5YVStjPLpcsc" alt=""><figcaption><p>Architecture</p></figcaption></figure>

WitnessChain Watchtowers' software stack comprise of &#x20;

1. Node Client (written in Go)&#x20;
2. On-chain Smart Contracts on Ethereum
3. Transaction Tracer APIs (for dApps to consume and configure the status)

## Node client

At a high level, the process of validation in a watchtower node client has 4 stages

1. Output State Root Extraction from L1
2. Output State Root Extraction (Tracer execution) from L2 Node
3. Comparison
4. Smart Contract integration

<figure><img src="/files/2jXZLGH5e23VSXTvweMt" alt=""><figcaption><p>Sequence of Steps</p></figcaption></figure>

## List of Smart Contracts

<figure><img src="/files/TrUYl52QkeVvOvI9ovd1" alt=""><figcaption></figcaption></figure>

### 1. OperatorRegistry

This is Registry-type contract for keeping track of operators. It is used for registering and deregistering new operators. Only registered and delegated EigenLayer operators are allowed into the watchtower network

### *<mark style="color:green;">addToOperatorWhitelist()</mark>*

| **Called By** | Contract Owner |
| ------------- | -------------- |
| **Returns**   | None           |
| **Emits**     | None           |

* Adds the list of operators to the whitelist mapping

### *<mark style="color:green;">removeFromOperatorWhitelist</mark>*<mark style="color:green;">()</mark>

| **Called By** | Contract Owner |
| ------------- | -------------- |
| **Returns**   | None           |
| **Emits**     | None           |

* Removes the list of operators from the whitelist mapping

### *<mark style="color:green;">register</mark>*

| **Called By** | Node operator |
| ------------- | ------------- |
| **Returns**   | None          |
| **Emits**     | None          |

* Registers the operator as a watchtower

### *<mark style="color:green;">deRegister</mark>*

| **Called By** | Node operator |
| ------------- | ------------- |
| **Returns**   | None          |
| **Emits**     | None          |

* Deregisters the operator as a watchtower

### 2. DiligenceProofManager

The DiligenceProofManager Contract contains functionality for miners (aka Watchtowers) to submit (mine) their Proofs of Diligence for a Bounty Period (which is the period between 2 L2 Txn Batch submissions). After the next L2 output state root is posted on L1, the bounty is rewarded to the miner. Bounties are given for every L2 Output (L2 Block).&#x20;

### *<mark style="color:green;">setBounty(chainID, amount)</mark>*

| **Called By** | Owner of the Contract      |
| ------------- | -------------------------- |
| **Returns**   | None                       |
| **Emits**     | NewBountyInitialized event |

* The owner of the Contract sets the Bounty Amount.
* Consider bounties are just reward points for now. Lets say 1 point for every L2 block mined successfully by a WatchTower.

### *<mark style="color:green;">submitProof (chainID, l2\_blockNumber, proofOfDiligence, signedProofOfDiligence)</mark>*

| **Called By** | WatchTower (EigenLayer Node Operator) |
| ------------- | ------------------------------------- |
| **Returns**   | None                                  |
| **Emits**     | NewBountyClaimed event                |

* Watchtower(s) submits/mine a L2 block by submitting the Hash(intermediate state root) and signing the Hash.
* Validations on Contract take care if the right sender is sending this transaction and if the blockNumber is a valid block to be mined.
* If the validations go through, the watchtower’s claim is accepted into the bounty, waiting for the rewardBounty to be called at the end of the mining cycle (which is roughly 60 mins on Optimism)

### *<mark style="color:green;">rewardBounty (chainID, l2\_blockNumber)</mark>*

| **Called By** | Owner                      |
| ------------- | -------------------------- |
| **Returns**   | Winner(WatchTower address) |
| **Emits**     | NewBountyRewarded event    |

* A reward (credit point) is awarded for every L2Block successfully mined by a miner using the **MIN logic**
* When the L2 Block Number moves on to the next one on L2OracleOutput, the bounty is rewarded to the miner (based on minimum submitted hash logic)

### 3. AlertManager

This contract is used for keeping track of alerts raised by watchtowers

### *<mark style="color:green;">raiseAlert()</mark>*

| **Called By** | Node Operator              |
| ------------- | -------------------------- |
| **Returns**   | Winner(WatchTower address) |
| **Emits**     | NewBountyRewarded event    |

* Raise an alert when there is a mismatch in output root between what is exeucte on L2 Node and asserted on L1 Contract

### *<mark style="color:green;">getAlerts(chainID,L2BlockNumber)</mark>*

| **Called By** | Node Operator              |
| ------------- | -------------------------- |
| **Returns**   | Winner(WatchTower address) |
| **Emits**     | NewBountyRewarded event    |

* Get all alerts raised so far a particular chainID and L2BlockNumber

## Assumptions

* Currently, watch Period is defined by the L2 Block Number that is obtained from the L2OutputOracle contract. So, a watchtower has to mine for that L2 block number. Any block numbers in the future or in the past will be rejected in the Contract.
* One WatchTower can mine only 1 bounty during that period for that L2 block number.
* With the current configuration, every WatchTower client runs an archived L2 node.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.witnesschain.com/archive/watchtower-protocol-architecture-v1/watchtower-architecture.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
