Skip to main content

API Reference

DaveConsensus Contract


DaveConsensus (also referred to as PRT-Rollups Consensus) is the consensus contract for applications that use Dave-style tournaments (such as PRT) for verification. This contract is responsible for validating a single application, whose inputs must originate from a pre-configured InputBox contract.

DaveConsensus manages epochs, which are defined as half-open block-number intervals of the form [a, b). Epochs are numbered sequentially starting from 0.

Off-chain nodes can track progress by subscribing to the EpochSealed event. This event indicates which epochs have been sealed, which ones are fully settled, and which epoch is currently open for challenges. Anyone may settle an epoch by calling settle(), and an epoch’s eligibility for settlement can be checked via canSettle(). Learn more about epochs here.

This contract links input ingestion, epoch progression, and Dave tournament-based verification under a single consensus interface.

canSettle()

function canSettle() external view returns (bool isFinished, uint256 epochNumber, Tree.Node winnerCommitment)

Check if the current epoch can be settled by querying the tournament's arbitration result.

Returns:

NameTypeDescription
isFinishedboolWhether the current sealed epoch tournament has finished
epochNumberuint256Current sealed epoch number
winnerCommitmentTree.NodeWinner's commitment in case the tournament has finished

settle()

function settle(uint256 epochNumber, bytes32 outputsMerkleRoot, bytes32[] calldata proof) external

Settle the current sealed epoch. On success, it emits an EpochSealed event.

Parameters:

NameTypeDescription
epochNumberuint256The current sealed epoch number (used to avoid race conditions)
outputsMerkleRootbytes32The post-epoch outputs Merkle root (used to validate outputs)
proofbytes32[]The bottom-up Merkle proof of the outputs Merkle root in the final machine state

getCurrentSealedEpoch()

function getCurrentSealedEpoch() external view returns (uint256 epochNumber, uint256 inputIndexLowerBound, uint256 inputIndexUpperBound, ITournament tournament)

Get information about the current sealed epoch including bounds and tournament.

Returns:

NameTypeDescription
epochNumberuint256Current epoch number
inputIndexLowerBounduint256Lower bound of input indices (inclusive)
inputIndexUpperBounduint256Upper bound of input indices (exclusive)
tournamentITournamentThe tournament that will decide the post-epoch state

isOutputsMerkleRootValid()

function isOutputsMerkleRootValid(address appContract, bytes32 outputsMerkleRoot) public view override returns (bool)

Validate whether a given outputs Merkle root is valid for the specified application.

Parameters:

NameTypeDescription
appContractaddressApplication contract address to validate against
outputsMerkleRootbytes32Outputs Merkle root hash to validate

Returns:

IndexTypeDescription
[0]boolWhether the outputs Merkle root is valid

provideMerkleRootOfInput()

function provideMerkleRootOfInput(uint256 inputIndexWithinEpoch, bytes calldata input) external view override returns (bytes32)

Get the Merkle root for input data at a specific index within the current epoch.

Parameters:

NameTypeDescription
inputIndexWithinEpochuint256Index of input within the current epoch
inputbytesInput data bytes to process

Returns:

IndexTypeDescription
[0]bytes32Merkle root of the input data

ConsensusCreation

event ConsensusCreation(IInputBox inputBox, address appContract, ITournamentFactory tournamentFactory)

An event emitted when a new DaveConsensus contract is deployed.

Parameters:

NameTypeDescription
inputBoxIInputBoxThe input box contract
appContractaddressThe application contract
tournamentFactoryITournamentFactoryThe tournament factory contract

EpochSealed

event EpochSealed(uint256 epochNumber, uint256 inputIndexLowerBound, uint256 inputIndexUpperBound, Machine.Hash initialMachineStateHash, bytes32 outputsMerkleRoot, ITournament tournament)

An event emitted when a new epoch is sealed.

Parameters:

NameTypeDescription
epochNumberuint256The epoch number
inputIndexLowerBounduint256The lower bound of the input index (inclusive)
inputIndexUpperBounduint256The upper bound of the input index (exclusive)
initialMachineStateHashMachine.HashThe initial machine state hash
outputsMerkleRootbytes32The Merkle root hash of the outputs tree
tournamentITournamentThe sealed epoch tournament contract

DaveAppFactory Contract


Dave-Application Factory contract allows anyone to reliably deploy an application validated with its corresponding Consensus contract.

newDaveApp()

function newDaveApp(bytes32 templateHash, bytes32 salt) external returns (IApplication appContract, IDaveConsensus daveConsensus)

Deploy a new Dave-Application pair deterministically.

Parameters:

NameTypeDescription
templateHashbytes32Template hash of the application
saltbytes32A 32-byte value used to add entropy to the addresses

Returns:

NameTypeDescription
appContractIApplicationDeployed application contract
daveConsensusIDaveConsensusDeployed DaveConsensus contract

calculateDaveAppAddress()

function calculateDaveAppAddress(bytes32 templateHash, bytes32 salt) external view returns (address appContractAddress, address daveConsensusAddress)

Calculate the deployment address for a Dave-App pair before deployment.

Parameters:

NameTypeDescription
appContractaddressApplication contract address
initialMachineStateHashMachine.HashInitial state hash of the Cartesi machine
saltbytes32Salt for CREATE2 address calculation

Returns:

NameTypeDescription
appContractAddressaddressCalculated deployment address for the application contract
daveConsensusAddressaddressCalculated deployment address for the DaveConsensus contract

DaveAppCreated

event DaveAppCreated(IApplication appContract, IDaveConsensus daveConsensus)

An event emitted when a new Dave-App pair is deployed.

Parameters:

NameTypeDescription
appContractIApplicationThe deployed application contract
daveConsensusIDaveConsensusThe deployed DaveConsensus contract
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.