Skip to main content

PRT Core Contracts

Tournament Factory Functions


Tournament factory contracts are responsible for instantiating and deploying tournaments. They handle the initialization of tournament parameters including initial machine state, data providers, and timing configurations. There are two main factory types: SingleLevelTournamentFactory for simple disputes and MultiLevelTournamentFactory for complex multi-level dispute resolution, which coordinates the creation of Top, Middle, and Bottom tournament instances.

instantiate()

function instantiate(Machine.Hash initialState, IDataProvider provider) external returns (ITournament)

Create a new single-level tournament instance.

Event Emitted: TournamentCreated(ITournament tournament) when tournament is created

Parameters:

NameTypeDescription
initialStateMachine.HashInitial machine state hash
providerIDataProviderData provider for input validation

Return Values:

IndexTypeDescription
[0]ITournamentCreated tournament instance

instantiateTop() (MultiLevelTournamentFactory)

function instantiateTop(Machine.Hash _initialHash, IDataProvider _provider) external returns (ITournament)

Create a new top-level tournament in the multi-level hierarchy.

Parameters:

NameTypeDescription
initialHashMachine.HashInitial machine state hash
providerIDataProviderData provider for input validation

Returns:

IndexTypeDescription
[0]TournamentCreated top tournament instance

instantiateMiddle()

function instantiateMiddle(Machine.Hash initialHash, Tree.Node contestedCommitmentOne, Machine.Hash contestedFinalStateOne, Tree.Node contestedCommitmentTwo, Machine.Hash contestedFinalStateTwo, Time.Duration allowance, uint256 startCycle, uint64 level, IDataProvider provider) external returns (ITournament)

Create a new middle-level tournament for dispute resolution.

Parameters:

NameTypeDescription
initialHashMachine.HashInitial machine state hash
contestedCommitmentOneTree.NodeFirst contested commitment
contestedFinalStateOneMachine.HashFirst contested final state
contestedCommitmentTwoTree.NodeSecond contested commitment
contestedFinalStateTwoMachine.HashSecond contested final state
allowanceTime.DurationTime allowance for participants
startCycleuint256Starting cycle for the tournament
leveluint64Tournament level in hierarchy
providerIDataProviderData provider for input validation

Returns:

IndexTypeDescription
[0]ITournamentCreated middle tournament instance

instantiateBottom()

function instantiateBottom(Machine.Hash initialHash, Tree.Node contestedCommitmentOne, Machine.Hash contestedFinalStateOne, Tree.Node contestedCommitmentTwo, Machine.Hash contestedFinalStateTwo, Time.Duration allowance, uint256 startCycle, uint64 level, IDataProvider provider) external returns (ITournament)

Create a new bottom-level tournament for leaf dispute resolution.

Parameters:

NameTypeDescription
initialHashMachine.HashInitial machine state hash
contestedCommitmentOneTree.NodeFirst contested commitment
contestedFinalStateOneMachine.HashFirst contested final state
contestedCommitmentTwoTree.NodeSecond contested commitment
contestedFinalStateTwoMachine.HashSecond contested final state
allowanceTime.DurationTime allowance for participants
startCycleuint256Starting cycle for the tournament
leveluint64Tournament level in hierarchy
providerIDataProviderData provider for input validation

Returns:

IndexTypeDescription
[0]ITournamentCreated bottom tournament instance

Tournament Core Functions


Core tournament contracts implement the asynchronous PRT-style dispute resolution mechanism. The abstract Tournament contract provides the foundational skeleton that resolves disputes among N parties in O(log N) depth under chess-clock timing, with asynchronous pairing where claims are matched as they arrive without requiring a prebuilt bracket. Concrete implementations include SingleLevelTournament for single-level disputes, TopTournament for the root of multi-level instances, MiddleTournament for intermediate levels, and BottomTournament for the leaf level that performs actual state transitions.

joinTournament()

function joinTournament(Machine.Hash finalState, bytes32[] calldata proof, Tree.Node leftNode, Tree.Node rightNode) external payable

Join a tournament by submitting a final computation hash with Merkle proof. Creates a match if another participant is waiting.

Parameters:

NameTypeDescription
finalStateTree.NodeFinal computational hash
proofbytes32[]Merkle proof for the final state
leftNodeTree.NodeLeft node of the commitment
rightNodeTree.NodeRight node of the commitment

arbitrationResult()

function arbitrationResult() external view returns (bool finished, Tree.Node winnerCommitment, Machine.Hash finalState)

Get the final arbitration result from the root tournament.

Return Values:

NameTypeDescription
finishedboolWhether the tournament is finished
winnerCommitmentTree.NodeThe winning commitment
finalStateMachine.HashFinal machine state hash of winner

advanceMatch()

function advanceMatch(Match.Id calldata matchId, Tree.Node leftNode, Tree.Node rightNode, Tree.Node newLeftNode, Tree.Node newRightNode) external

Advance a match by providing new intermediate nodes in the binary search process.

Parameters:

NameTypeDescription
matchIdMatch.IdIdentifier of the match to advance
leftNodeTree.NodeCurrent left node in the match
rightNodeTree.NodeCurrent right node in the match
newLeftNodeTree.NodeNew left node for next iteration
newRightNodeTree.NodeNew right node for next iteration

winMatchByTimeout()

function winMatchByTimeout(Match.Id calldata matchId, Tree.Node leftNode, Tree.Node rightNode) external

Win a match when the opponent has run out of time allowance.

Parameters:

NameTypeDescription
matchIdMatch.IdIdentifier of the match to win by timeout

eliminateMatchByTimeout()

function eliminateMatchByTimeout(Match.Id calldata matchId) external

Eliminate a match when both participants have run out of time.

Parameters:

NameTypeDescription
matchIdMatch.IdIdentifier of the match to eliminate

isFinished()

function isFinished() external view returns (bool)

Check if the tournament has finished (has a winner or is eliminated).

isClosed()

function isClosed() external view returns (bool)

Check if the tournament is closed to new participants.

bondValue()

function bondValue() external view returns (uint256)

Get the amount of Wei necessary to call joinTournament().

Return Values:

IndexTypeDescription
[0]uint256The tournament bond value

tryRecoveringBond()

function tryRecoveringBond() external returns (bool)

Try recovering the bond of the winner commitment submitter.

Return Values:

IndexTypeDescription
[0]boolWhether the recovery was successful

sealInnerMatchAndCreateInnerTournament()

function sealInnerMatchAndCreateInnerTournament(Match.Id calldata matchId, Tree.Node leftLeaf, Tree.Node rightLeaf, Machine.Hash agreeHash, bytes32[] calldata agreeHashProof) external

Seal an inner match and create a new inner tournament to resolve the dispute at a finer granularity.

Event Emitted: NewInnerTournament(Match.IdHash indexed matchIdHash, ITournament indexed childTournament) when inner tournament is created

Parameters:

NameTypeDescription
matchIdMatch.IdIdentifier of the match to seal
leftLeafTree.NodeLeft leaf node of the disagreement
rightLeafTree.NodeRight leaf node of the disagreement
agreeHashMachine.HashAgreed upon machine state hash
agreeHashProofbytes32[]Merkle proof for the agreed hash

winInnerTournament()

function winInnerTournament(ITournament childTournament, Tree.Node leftNode, Tree.Node rightNode) external

Process the result of a finished inner tournament and advance the parent match.

Parameters:

NameTypeDescription
childTournamentITournamentThe inner/child tournament
leftNodeTree.NodeLeft child of the winning commitment
rightNodeTree.NodeRight child of the winning commitment

eliminateInnerTournament()

function eliminateInnerTournament(ITournament childTournament) external

Eliminate an inner tournament that has no winner and advance the parent match.

Parameters:

NameTypeDescription
childTournamentITournamentThe inner/child tournament to eliminate

innerTournamentWinner()

function innerTournamentWinner() external view returns (bool, Tree.Node, Tree.Node, Clock.State memory)

Get the winner information from a finished inner tournament for parent tournament processing.

Returns:

IndexTypeDescription
[0]boolWhether the tournament is finished
[1]Tree.NodeThe contested parent commitment
[2]Tree.NodeThe winning inner commitment
[3]Clock.StatePaused clock state of the winning inner commitment

canBeEliminated()

function canBeEliminated() external view returns (bool)

Check if the tournament can be safely eliminated by its parent.

Returns:

IndexTypeDescription
[0]boolWhether the tournament can be eliminated

Other View Functions


tournamentArguments()

function tournamentArguments() external view returns (TournamentArguments memory)

Get the tournament arguments.

Return Values:

IndexTypeDescription
[0]TournamentArgumentsThe tournament arguments

canWinMatchByTimeout()

function canWinMatchByTimeout(Match.Id calldata matchId) external view returns (bool)

Check if a match can be won by timeout.

Parameters:

NameTypeDescription
matchIdMatch.IdThe identifier of the match

Return Values:

IndexTypeDescription
[0]boolWhether the match can be won by timeout

getCommitment()

function getCommitment(Tree.Node commitmentRoot) external view returns (Clock.State memory clock, Machine.Hash finalState)

Get the clock and final state of a commitment.

Parameters:

NameTypeDescription
commitmentRootTree.NodeThe root of the commitment

Return Values:

IndexTypeDescription
[0]Clock.StateThe clock state of the commitment
[1]Machine.HashThe final state of the commitment

getMatch()

function getMatch(Match.IdHash matchIdHash) external view returns (Match.State memory)

Get the match state for a given match identifier.

Parameters:

NameTypeDescription
matchIdHashMatch.IdHashThe identifier of the match

Return Values:

IndexTypeDescription
[0]Match.StateThe state of the match

getMatchCycle()

function getMatchCycle(Match.IdHash matchIdHash) external view returns (uint256)

Get the running machine cycle of a match by its ID hash.

Parameters:

NameTypeDescription
matchIdHashMatch.IdHashThe identifier of the match

Return Values:

IndexTypeDescription
[0]uint256The cycle of the match

tournamentLevelConstants()

function tournamentLevelConstants() external view returns (uint64 maxLevel, uint64 level, uint64 log2step, uint64 height)

Get the level constants of a tournament.

Return Values:

NameTypeDescription
maxLeveluint64The maximum number of levels in the tournament
leveluint64The current level of the tournament
log2stepuint64The log2 number of steps between commitment leaves
heightuint64The height of the commitment tree

timeFinished()

function timeFinished() external view returns (bool, Time.Instant)

Get the confirmation and time when the tournament finished.

Return Values:

IndexTypeDescription
[0]boolWhether the tournament has finished
[1]Time.InstantThe time when the tournament finished

Events Emitted


TournamentCreated()

event TournamentCreated(ITournament tournament)

An event emitted when a new tournament is instantiated.

Parameters:

NameTypeDescription
tournamentITournamentThe tournament with its arguments

CommitmentJoined()

event CommitmentJoined(Tree.Node commitmentRoot, Machine.Hash finalState, address claimer)

An event emitted when a commitment is successfully added.

Parameters:

NameTypeDescription
commitmentRootTree.NodeThe root of the commitment
finalStateMachine.HashThe final computational hash
claimeraddressThe address of the claimer

PartialBondRefund()

event PartialBondRefund(address indexed recipient, uint256 value, bool indexed success, bytes ret)

An event emitted when a partial bond refund is successful.

Parameters:

NameTypeDescription
recipientaddressThe address of the recipient
valueuint256The amount of the refund
successboolWhether the refund was successful
retbytesThe return data of the refund

NewInnerTournament()

event NewInnerTournament(Match.IdHash indexed matchIdHash, ITournament indexed childTournament)

An event emitted when a new inner tournament is created.

Parameters:

NameTypeDescription
matchIdHashMatch.IdHashHashed Identifier of the match
childTournamentITournamentThe inner/child tournament

MatchCreated()

event MatchCreated(Match.IdHash indexed matchIdHash, Tree.Node indexed one, Tree.Node indexed two, Tree.Node leftOfTwo)

An event emitted when a new match is created.

Parameters:

NameTypeDescription
matchIdHashMatch.IdHashIdentifier of the match
oneTree.NodeOne of the participants
twoTree.NodeTwo of the participants
leftOfTwoTree.NodeLeft node of the two

MatchAdvanced()

event MatchAdvanced(Match.IdHash indexed matchIdHash, Tree.Node otherParent, Tree.Node leftNode)

An event emitted when a match is advanced.

Parameters:

NameTypeDescription
matchIdHashMatch.IdHashHashed Identifier of the match
otherParentTree.NodeThe new otherParent value
leftNodeTree.NodeThe new leftNode value

MatchDeleted()

event MatchDeleted(Match.IdHash indexed matchIdHash, Tree.Node indexed one, Tree.Node indexed two, MatchDeletionReason reason, WinnerCommitment winnerCommitment)   

An event emitted when a match is deleted.

Parameters:

NameTypeDescription
matchIdHashMatch.IdHashHashed Identifier of the match
oneTree.NodeCommitment of the 1st participant
twoTree.NodeCommitment of the 2nd participant
reasonMatchDeletionReasonThe reason for the deletion
winnerCommitmentWinnerCommitmentThe winner commitment
We use cookies to ensure that we give you the best experience on our website. By using the website, you agree to the use of cookies.