npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cartesi/arbitration

v0.8.0

Published

Arbitration DLib

Downloads

371

Readme

:warning: The Cartesi team keeps working internally on the next version of this repository, following its regular development roadmap. Whenever there's a new version ready or important fix, these are published to the public source tree as new releases.

Arbitration D-Lib

ArbitrationLib is the combination of the on-chain protocol and off-chain protocol that work together to resolve any disputes that might occur during the execution of a Cartesi Dapp. The behavior of the off-chain and on-chain code are very similar. The on-chain code is written in Solidity and the off-chain in Rust.

Most of the Solidity contracts in this repository follow the Instantiator design pattern.

Arbitration Test Instantiator

The Arbitration Test contract is a simplified contract that simulates the behavior of a Dapp when two participants disagree with each other. It's inital state, after being instantiated, is Idle. The Challenger requests the state changing to Waiting state and instantiates a compute instance for future computation. Only after the compute ends, the participants can claim the state to be Finished. A working demo and be found at https://github.com/cartesi/demo/.

// These are the possible states and transitions of the contract.

// +---+
// |   |
// +---+
//   |
//   | constructor
//   v
// +------+
// | Idle |
// +------+
//   |
//   | claimWaiting
//   v
// +---------+
// | Waiting |
// +---------+
//   |
//   | claimFinished
//   v
// +----------+
// | Finished |
// +----------+

Compute Instantiator

A Compute contract is instantiated with a computation proposal. It's inital state, after being instantiated, is WaitingClaim. There is a deadline, therefore, for the Claimer to submit a result to the proposed computation. After the Claimer submits a final hash for that proposal, there is a period in which the Challenger can either accept or challenge that result.

If the result is accepted we reach a Consensus state. If not, the dispute is resolved through a Verification Game.

The possible states of an instance of this contract are:

// +---+
// |   |
// +---+
//   |
//   | instantiate
//   v
// +--------------+ claimVictoryByTime +-----------------------+
// | WaitingClaim |------------------->| ClaimerMisseddeadline |
// +--------------+                    +-----------------------+
//   |
//   | submitClaim
//   v
// +---------------------+  confirm    +-----------------+
// | WaitingConfirmation |------------>| ConsensusResult |
// +---------------------+ or deadline +-----------------+
//   |
//   | challenge
//   v
// +------------------+ winByVG        +---------------+
// | WaitingChallenge |--------------->| ChallengerWon |
// +------------------+                +---------------+
//   |
//   |
//   |                  winByVG        +------------+
//   +-------------------------------->| ClaimerWon |
//                                     +------------+

VG Instantiator

The Verification Game Instantiator is responsible for solving the disputes that may arise during the Compute Instantiator execution. It is evoked when a Claimed result gets challenged.

The first step of a Verification Game is finding the divergence point, which is done by the Partition Instantiator contract (detailed in the following section).

If the Partition Instantiator concludes successfully, the VG moves to the MemoryManager phase, in which the Claimer has to fill the MM with the activity log. This phase is also better described in a following section.

After the Memory Manager is filled with the necessary data, VG contract settles the game instantiating a machine and running one step on it.By checking the final hash generated by the step, the VG instantiator can define the winner. The Step transition is further explained in theSolidity Machine Repo.

These are the possible states and transitions of the contract.

//
//               +---+
//               |   |
//               +---+
//                 |
//                 | instantiate
//                 v
//               +----------------+  winByPartitionTimeout
//   +-----------| WaitPartition  |------------------------+
//   |           +----------------+                        |
//   |                         |                           |
//   | winByPartitionTimeout   | startMachineRunChallenge  |
//   |                         v                           |
//   |           +-----------------------+                 |
//   | +---------| WaitMemoryProveValues |---------------+ |
//   | |         +-----------------------+               | |
//   | |                                                 | |
//   | |claimVictoryByDeadline   settleVerificationGame  | |
//   v v                                                 v v
// +--------------------+               +-----------------------+
// | FinishedClaimerWon |               | FinishedChallengerWon |
// +--------------------+               +-----------------------+
//

Partition Instantiator

The Partition contract is responsible for the interactions between Alice and Bob while they find the divergence point (the exact step performed during the computation in which they agree with the inital hash but disagree with the final one).

The possible states of an instance of this contract are:

//
//          +---+
//          |   |
//          +---+
//            |
//            | instantiate
//            v
//          +---------------+  claimVictoryByTimeout  +---------------+
//          | WaitingHashes |------------------------>| ChallengerWon |
//          +---------------+                         +---------------+
//            |  ^
// replyQuery |  | makeQuery
//            v  |
//          +--------------+   claimVictoryByTimeout  +------------+
//          | WaitingQuery |------------------------->| ClaimerWon |
//          +--------------+                          +------------+
//            |
//            | presentDivergence
//            v
//          +-----------------+
//          | DivergenceFound |
//          +-----------------+
//

MemoryManager Instantiator

When a dispute arises and a machine run challenge begins, the Claimer is responsible to send their off-chain state access log to the MemoryManager instance referent to that Verification Game.

The information sent by them is consumed by the RISC-V Solidity emulator as if the entire state content was available - since the off and on-chain emulators match down to the order in which accesses are logged.

The MemoryManager contract offers the RISC-V Solidity emulator a very simple interface that consists of:

  • read - reads a word in a specific address.
  • write - writes a word in a specific address.
  • finishReplayPhase - signals that the Step has completed.

It also makes sure that all accesses performed by the Step function match the ones provided by the Claimer and are consistent with the Merkle proofs provided by him. If that is not the case, the Claimer loses the dispute.

The possible states of an instance of this contract are:

//
// +---+
// |   |
// +---+
//   |
//   | instantiate
//   v
// +---------------+    | proveRead
// | WaitingProofs |----| proveWrite
// +---------------+
//   |
//   | finishProofPhase
//   v
// +----------------+    |read
// | WaitingReplay  |----|write
// +----------------+
//   |
//   | finishReplayPhase
//   v
// +----------------+
// | FinishedReplay |
// +----------------+
//

Getting Started - on-chain code

Install

Install dependencies

npm install

Compile contracts with

npm run build

Having a node listening to 8545, you can deploy using

npm run deploy

Run tests

Migrate contracts and prepare testing files ./deploy_development.sh

Run tests ./run_python_tests.sh

Getting Started - off-chain code

Install

Install rust curl https://sh.rustup.rs -sSf | sh

Add cargo to your path in .bashrc export PATH=$PATH:/home/user/.cargo/bin

Move to compute dir: cd compute

Build project: cargo build

TODO

Use safemath on contracts

Protect against replay attacks

Review if events are appropriate for light client

Contributing

Thank you for your interest in Cartesi! Head over to our Contributing Guidelines for instructions on how to sign our Contributors Agreement and get started with Cartesi!

Please note we have a Code of Conduct, please follow it in all your interactions with the project.

Authors

  • Augusto Teixeira

License

Note: This component currently has dependencies that are licensed under the GNU GPL, version 3, and so you should treat this component as a whole as being under the GPL version 3. But all Cartesi-written code in this component is licensed under the Apache License, version 2, or a compatible permissive license, and can be used independently under the Apache v2 license. After this component is rewritten, the entire component will be released under the Apache v2 license. The arbitration d-lib repository and all contributions are licensed under GPL 3. Please review our COPYING file.