Counterfactual is a general framework for building state channel applications.
-
Generalized: Counterfactual makes no assumptions about your application, the type of state being passed around, the number of parties in the channel, the type of asset being stored, or the structure of your application. It is fully generalized to support any number of state channel applications for n-party channels with zero on-chain transactions for installing or uninstalling applications.
-
Modular: Write your application logic without concerning yourself with the details of the state channel dispute process, timeout periods, or for edge case attack scenarios. Counterfactual aims to seperate the state channel logistics from your application logistics. Applications themselves, despite being secured through the same on-chain multisignature wallet, are completely isolated from each other.
-
Maximally Off-Chain: The only on-chain component for a state channel in Counterfactual is a multisignature wallet. Everything else is supported through the technique of counterfactual instantiation (i.e., generating deterministic references to off-chain contract code).
Counterfactual provides a small and clean API for application developers to program against. It is designed to allow a clean separation of application-specific code written by an app developer and framework written by us. Application-specific code is isolated in a stateless contract. Examples of these contracts can be seen in the repository cf-apps
.
When disputes occur, an instance of the contract StateChannel.sol
is placed on chain together with a small amount of state. This contract also manages the dispute flow. Upon resolution of a dispute, apps return a struct called Transfer.Details
to determine who gets the value-at-stake, and for common types of value-at-stake, the framework enforces a maximum amount of value transferable.
State deposit is stored in a multisig wallet. Apps are installed by signing commitments from the multisig. Deterministic addressing for counterfactually instantiated objects is provided through a registry.
For a more detailed description of contract architecture, please see ARCHITECTURE.md.
If you find a security issue, please contact us at security@counterfactual.com.
The main purpose of this repository is to continue to evolve Counterfactual's contracts layer, iterating towards improving it for production use. Development of Counterfactual happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements.
- Install node v8.x or v10.x
yarn
To run the tests:
- Run
yarn ganache
in a separate terminal yarn test
Counterfactual is MIT licensed.