Using Counterfactual Approaches For Referral Networks

Should the 2key network apply counterfactual contracts to improve performance?

In this article, I'd like to discuss the use of counterfactual contracts in the 2key network. 2key Network is a blockchain-based referral network intended to reward referrers through smart contracts. Referrals progress through the network thanks to people sharing them through their regular browsers. Therefore, 2key generates off-chain cryptographically signed links, which propagate among users without reaching the blockchain. Upon conversion, a user submits the signed link to the smart contract. The smart contract rewards the chain of referrers as represented in the signed link. The smart contract is deployed per referral campaign by the campaign initiator, depositing a referral reward, as an amount of cryptocurrency, from which the smart contract will later pay the referrers.

State Channels

A state channel (also called a payment channel) is an off-chain mechanism where the two sides of the channel, henceforth called the sender and receiver, deploy a smart contract to which one side, the sender, deposits an amount of cryptocurrency. Upon pre-agreed off-chain events, the sender transmits to the receiver cryptographically signed messages, with each message overriding the previous one. Each message commits the sender to pay an amount of cryptocurrency to the receiver. This commitment can be turned into an actual payment by the receiver submitting a transaction to the smart contract.

State channels can be generalized to multi-party state channels, involving more than two parties, where again there is an initial deposit of cryptocurrency into the state channel that serves as a guarantee for enforcing of future commitments.

It should be noted that state channels require a priori knowledge of the parties to the channel.

Constructions like the Raiden Network may use intermediaries that are unknown beforehand to construct a two-party state channel, but the two parties are known in advance.

2key Campaign as a State Chanel

In essence, with the 2key signed link, the campaign smart contract constructs a multi-party state channel with a star structure from the initiator of the campaign to the referrers.

This star structure is built dynamically as referral progresses through the campaign. The referrers are guaranteed that upon conversion when they reach the smart contract for a reward they will actually get it.

In stark contrast to state channels, there is no requirement for initial knowledge of the parties involved. In fact, the originator has no prior knowledge who the eventual referrers will be. All the initiator knows is those referrers from which the campaign starts (called the source seeding).

Moreover, the deposit of cryptocurrency is required from the initiator of the campaign.

2key's unique novelty is in building the state channel through the cryptographically signed link. Thus, there is no need for exchange of commitments, as the signed link serves as a commitment. Moreover, this commitment involves multiple parties.

Counterfactual

Counterfactual is a protocol for off-chain blockchain, consisting of a library for off-chain applications, an intuitive generalized state channels protocol, and a set of Ethereum smart contracts. Counterfactual generalizes state channels by exchanging cryptographically signed transactions between the parties to the channel. These transactions can include deployment of contracts and calls to functions of smart contracts.

Counterfactual means something that could be true but is not. This is an extremely helpful concept when discussing state channels, where we spend a lot of time reasoning about things that could be happening on chain but are not.

In state channels, we say counterfactual X to describe a case where:

X could happen on the chain but doesn't.

Any participant can unilaterally make X happen on-chain.

Participants can, therefore, act as though X has happened on-chain"

Counterfactual is based on a set of smart contracts that are installed on the blockchain, with each Dapp developer wishing to construct a state channel using its library, and installing a multisig wallet with a deposit to start the state channel.

Clearly, by exchanging messages that represent the deployment of smart contracts and call to methods of smart contracts, Counterfactual enables more powerful state channels in the sense of carrying more complex interactions off-chain.

However, in contrast to 2key, Counterfactual requires the parties to a state channel, to construct a multisig wallet with a cryptocurrency deposit in order to initiate a state channel. Hence, the parties to the state channel have to be known in advance.

2key Signed Link as a Generalised State Channel Protocol

A signed link carries a commitment for a payment for a path of referrals. So a signed link is an off-chain state channel involving multiple parties. With counterfactual thinking, a signed link represents something that will occur on the blockchain if submitted. But this referral reward to all referrer parties will occur only upon conversion.

So far we described our initial construction of the 2key signed link as a sequence of referrals that is cryptographically signed. This was the initial concept that we elaborated since.

First, we generalized the signed link from containing the path of referrers as a sequence of addresses of referrer to contain small pieces of state. For example, for a voting contract, the piece of state will be the vote.

Realizing the limitation of storing information in a link, we moved the sequence of referrer and the piece of state to a centralized storage, using IPFS. Hence, the signed link contains a hash of that path and the state.

Now, examining the Counterfactual mechanism of employing the state channel, it is evident that it depends on the Dapp using their library. In contrast, 2key wanted its signed link to be constructed by a regular browser using JavaScript.

There are two approaches to having the browser of a referrer participate in constructing a signed link. The centralized approach requires the user to go to a 2key website, where the referrer will get a referral link. We chose the decentralized approach, where the code to construct the link resides in decentralized storage. The link contains a hash to that code.

So, the 2key link has this structure:

{node-code-hash}&{state-hash}

Where node-code-hash is the hash to the JavaScript code to construct the link, and the state-hash is a hash to the combined state and referral address, which are cryptographically signed.

The Dapp using the 2key link is itself served from decentralized storage. Thereby, the 2key multi-party state channel operates in a completely decentralized way through standard browsers.

Conclusions

We believe 2key possesses many of the attributes of Counterfactual, such as multi-party state channels. Moreover, 2key is superior in terms of decentralization as it does not require prior knowledge of the participants in the state channel, and it operates through standard browsers.