Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cartesi-rollups/contracts/test/DaveConsensus.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ contract MockTournament is ITournament {
return true;
}

error NotImplemented();

function bondValue() external pure override returns (uint256) {
revert NotImplemented();
}
Expand Down Expand Up @@ -146,10 +148,6 @@ contract MockTournament is ITournament {
revert NotImplemented();
}

function nonRootTournamentArgs() external pure override returns (NonRootArguments memory) {
revert NotImplemented();
}

function canWinMatchByTimeout(Match.Id calldata) external pure override returns (bool) {
revert NotImplemented();
}
Expand Down
5 changes: 2 additions & 3 deletions prt/client-rs/core/src/tournament/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::tournament::{
TournamentWinner,
};
use cartesi_dave_merkle::Digest;
use cartesi_prt_contracts::{non_leaf_tournament, tournament};
use cartesi_prt_contracts::tournament;

#[derive(Clone)]
pub struct StateReader {
Expand All @@ -37,8 +37,7 @@ impl StateReader {
tournament_address: Address,
match_id: MatchID,
) -> Result<Option<TournamentCreatedEvent>> {
let tournament =
non_leaf_tournament::NonLeafTournament::new(tournament_address, &self.client);
let tournament = tournament::Tournament::new(tournament_address, &self.client);
let events = tournament
.NewInnerTournament_filter()
.address(tournament_address)
Expand Down
14 changes: 7 additions & 7 deletions prt/client-rs/core/src/tournament/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ruint::aliases::U256;

use crate::{machine::MachineProof, tournament::MatchID};
use cartesi_dave_merkle::{Digest, MerkleProof};
use cartesi_prt_contracts::{leaf_tournament, non_leaf_tournament, tournament};
use cartesi_prt_contracts::tournament;

#[derive(Clone, Debug)]
pub struct EthArenaSender {
Expand Down Expand Up @@ -167,7 +167,7 @@ impl ArenaSender for EthArenaSender {
right_leaf: Digest,
initial_hash_proof: &MerkleProof,
) -> Result<()> {
let tournament = non_leaf_tournament::NonLeafTournament::new(tournament, &self.provider);
let tournament = tournament::Tournament::new(tournament, &self.provider);
let initial_hash_siblings = initial_hash_proof
.siblings
.iter()
Expand All @@ -193,7 +193,7 @@ impl ArenaSender for EthArenaSender {
left_node: Digest,
right_node: Digest,
) -> Result<()> {
let tournament = non_leaf_tournament::NonLeafTournament::new(tournament, &self.provider);
let tournament = tournament::Tournament::new(tournament, &self.provider);
let tx_result = tournament
.winInnerTournament(child_tournament, left_node.into(), right_node.into())
.send()
Expand All @@ -208,7 +208,7 @@ impl ArenaSender for EthArenaSender {
left_node: Digest,
right_node: Digest,
) -> Result<()> {
let tournament = non_leaf_tournament::NonLeafTournament::new(tournament, &self.provider);
let tournament = tournament::Tournament::new(tournament, &self.provider);
let tx_result = tournament
.winMatchByTimeout(match_id.into(), left_node.into(), right_node.into())
.send()
Expand All @@ -224,7 +224,7 @@ impl ArenaSender for EthArenaSender {
right_leaf: Digest,
initial_hash_proof: &MerkleProof,
) -> Result<()> {
let tournament = leaf_tournament::LeafTournament::new(tournament, &self.provider);
let tournament = tournament::Tournament::new(tournament, &self.provider);
let initial_hash_siblings = initial_hash_proof
.siblings
.iter()
Expand All @@ -251,7 +251,7 @@ impl ArenaSender for EthArenaSender {
right_node: Digest,
proofs: MachineProof,
) -> Result<()> {
let tournament = leaf_tournament::LeafTournament::new(tournament, &self.provider);
let tournament = tournament::Tournament::new(tournament, &self.provider);
let tx_result = tournament
.winLeafMatch(
match_id.into(),
Expand All @@ -278,7 +278,7 @@ impl ArenaSender for EthArenaSender {
tournament: Address,
inner_tournament: Address,
) -> Result<()> {
let tournament = non_leaf_tournament::NonLeafTournament::new(tournament, &self.provider);
let tournament = tournament::Tournament::new(tournament, &self.provider);
let tx_result = tournament
.eliminateInnerTournament(inner_tournament)
.send()
Expand Down
18 changes: 0 additions & 18 deletions prt/client-rs/core/src/tournament/tournament.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@ impl From<MatchID> for cartesi_prt_contracts::tournament::Match::Id {
}
}

impl From<MatchID> for cartesi_prt_contracts::non_leaf_tournament::Match::Id {
fn from(match_id: MatchID) -> Self {
cartesi_prt_contracts::non_leaf_tournament::Match::Id {
commitmentOne: match_id.commitment_one.into(),
commitmentTwo: match_id.commitment_two.into(),
}
}
}

impl From<MatchID> for cartesi_prt_contracts::leaf_tournament::Match::Id {
fn from(match_id: MatchID) -> Self {
cartesi_prt_contracts::leaf_tournament::Match::Id {
commitmentOne: match_id.commitment_one.into(),
commitmentTwo: match_id.commitment_two.into(),
}
}
}

/// Struct used to communicate the state of a commitment.
#[derive(Clone, Copy, Debug)]
pub struct CommitmentState {
Expand Down
2 changes: 1 addition & 1 deletion prt/contracts/justfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BINDINGS_DIR := "./bindings-rs/src/contract"
DEPLOYMENTS_DIR := "./deployments"
SRC_DIR := "."
BINDINGS_FILTER := "^[^I].+TournamentFactory|LeafTournament|^Tournament$"
BINDINGS_FILTER := "^[^I].+TournamentFactory|^Tournament$"

default: build

Expand Down
57 changes: 5 additions & 52 deletions prt/contracts/script/Deployment.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,10 @@ import {
import {
RiscVStateTransition
} from "src/state-transition/RiscVStateTransition.sol";
import {BottomTournament} from "src/tournament/concretes/BottomTournament.sol";
import {MiddleTournament} from "src/tournament/concretes/MiddleTournament.sol";
import {TopTournament} from "src/tournament/concretes/TopTournament.sol";
import {Tournament} from "src/tournament/Tournament.sol";
import {
MultiLevelTournamentFactory
} from "src/tournament/factories/MultiLevelTournamentFactory.sol";
import {
BottomTournamentFactory
} from "src/tournament/factories/multilevel/BottomTournamentFactory.sol";
import {
MiddleTournamentFactory
} from "src/tournament/factories/multilevel/MiddleTournamentFactory.sol";
import {
TopTournamentFactory
} from "src/tournament/factories/multilevel/TopTournamentFactory.sol";
import {Time} from "src/tournament/libs/Time.sol";

type Milliseconds is uint64;
Expand Down Expand Up @@ -188,43 +177,9 @@ contract DeploymentScript is BaseDeploymentScript {
)
);

address topTournament = _storeDeployment(
type(TopTournament).name,
_create2(type(TopTournament).creationCode, abi.encode())
);

address middleTournament = _storeDeployment(
type(MiddleTournament).name,
_create2(type(MiddleTournament).creationCode, abi.encode())
);

address bottomTournament = _storeDeployment(
type(BottomTournament).name,
_create2(type(BottomTournament).creationCode, abi.encode())
);

address topTournamentFactory = _storeDeployment(
type(TopTournamentFactory).name,
_create2(
type(TopTournamentFactory).creationCode,
abi.encode(topTournament)
)
);

address middleTournamentFactory = _storeDeployment(
type(MiddleTournamentFactory).name,
_create2(
type(MiddleTournamentFactory).creationCode,
abi.encode(middleTournament)
)
);

address bottomTournamentFactory = _storeDeployment(
type(BottomTournamentFactory).name,
_create2(
type(BottomTournamentFactory).creationCode,
abi.encode(bottomTournament)
)
address tournamentImpl = _storeDeployment(
type(Tournament).name,
_create2(type(Tournament).creationCode, abi.encode())
);

address canonicalTournamentParametersProvider = _storeDeployment(
Expand All @@ -240,9 +195,7 @@ contract DeploymentScript is BaseDeploymentScript {
_create2(
type(MultiLevelTournamentFactory).creationCode,
abi.encode(
topTournamentFactory,
middleTournamentFactory,
bottomTournamentFactory,
tournamentImpl,
canonicalTournamentParametersProvider,
cartesiStateTransition
)
Expand Down
38 changes: 22 additions & 16 deletions prt/contracts/src/ITournament.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pragma solidity ^0.8.17;

import {IDataProvider} from "prt-contracts/IDataProvider.sol";
import {IStateTransition} from "prt-contracts/IStateTransition.sol";
import {Clock} from "prt-contracts/tournament/libs/Clock.sol";
import {Commitment} from "prt-contracts/tournament/libs/Commitment.sol";
import {Match} from "prt-contracts/tournament/libs/Match.sol";
Expand All @@ -17,6 +18,17 @@ interface ITournament {
// Types
//

/// @notice Dispute information from a parent match.
/// @dev For non-root tournaments (level > 0), contains the two contested commitments
/// and final states from the parent match that created this tournament.
/// For root tournaments (level == 0), all fields are zero.
struct NestedDispute {
Tree.Node contestedCommitmentOne;
Machine.Hash contestedFinalStateOne;
Tree.Node contestedCommitmentTwo;
Machine.Hash contestedFinalStateTwo;
}

/// @notice Tournament arguments
/// @param commitmentArgs The commitment arguments
/// @param level The tournament level
Expand All @@ -26,10 +38,14 @@ interface ITournament {
/// @param maxAllowance The maximum time of a player clock
/// @param matchEffort The worst-case time to compute a commitment
/// @param provider The contract that provides input Merkle roots
/// @param nestedDispute Dispute information from parent match (zero for root tournaments)
/// @param stateTransition State transition contract, used by leaf-level operations
/// @param tournamentFactory Multi-level factory address (cast to IMultiLevelTournamentFactory when needed), used by non-leaf operations when instantiating inner tournaments
/// @dev A root tournament is at level 0.
/// A single-level tournament has 1 level.
/// A multi-level tournament has 2 or more levels.
/// Time is measured in base-layer blocks.
/// For root tournaments (level == 0), nestedDispute fields are zero.
struct TournamentArguments {
Commitment.Arguments commitmentArgs;
uint64 level;
Expand All @@ -39,17 +55,9 @@ interface ITournament {
Time.Duration maxAllowance;
Time.Duration matchEffort;
IDataProvider provider;
}

/// @notice Arguments for non-root tournaments (level > 0)
/// @dev Non-root tournaments are inner tournaments created by parent tournaments.
/// They need to track which two final states are being contested.
/// Root tournaments (level == 0) don't need these arguments.
struct NonRootArguments {
Tree.Node contestedCommitmentOne;
Machine.Hash contestedFinalStateOne;
Tree.Node contestedCommitmentTwo;
Machine.Hash contestedFinalStateTwo;
NestedDispute nestedDispute;
IStateTransition stateTransition;
address tournamentFactory; // Cast to IMultiLevelTournamentFactory when needed to avoid circular dependency
}

/// @notice Match deletion reason
Expand Down Expand Up @@ -214,7 +222,9 @@ interface ITournament {
uint256 commitment, Machine.Hash computed, Machine.Hash claimed
);
error WrongNodesForStep();
error NotImplemented();
error RequireLeafTournament();
error RequireNonLeafTournament();
error RequireNonRootTournament();

//
// Functions
Expand Down Expand Up @@ -432,10 +442,6 @@ interface ITournament {
returns (TournamentArguments memory);

/// @notice Returns non-root tournament arguments
function nonRootTournamentArgs()
external
view
returns (NonRootArguments memory);

/// @notice Check whether a match can be won by timeout.
/// @param matchId The match ID
Expand Down
Loading