> ## Documentation Index
> Fetch the complete documentation index at: https://kleros-mintlify-6ebc7975.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Sortition Module

> Sortition Module reference: PNK-weighted juror drawing, sum tree stakes, staking, generating, and drawing phases, and RNG integration in Kleros V2.

Manages juror selection through stake-weighted random drawing. Uses a sum tree data structure for efficient proportional selection.

**Version**: 0.9.0 | **Proxy**: UUPS Upgradeable

## Phase System

The sortition module operates in phases:

1. **Staking**: Jurors can update stakes. No draws happening.
2. **Generating**: RNG is requested from the random number source.
3. **Drawing**: Jurors are drawn for disputes using the generated random number.

Stakes submitted during Generating or Drawing phases are queued and applied when Staking phase resumes.

## Key Methods

### `createDisputeHook(uint256 _disputeID, uint256 _roundID)`

Called by KlerosCore when a dispute is created. Prepares the drawing parameters.

### `draw(uint256 _disputeID, uint256 _roundID, uint256 _nonce) → address`

Draws a juror for the dispute based on staked PNK weights and the random number.

### `setStake(address _account, uint96 _courtID, uint256 _newStake, bool _alreadyTransferred) → (uint256, uint256, uint256, bool)`

Updates a juror's stake in the sum tree.

## Stake Tree

Uses a sortition sum tree where each leaf represents a juror's stake in a court. Drawing probability is proportional to stake: a juror with 10% of total staked PNK in a court has a 10% chance of being drawn for each juror slot.

[View Source](https://github.com/kleros/kleros-v2/blob/dev/contracts/src/arbitration/SortitionModule.sol)
