Connecting Nash to the blockchain: State channel smart contracts

The heart of Nash is our matching engine, which we described in this article as a multi-chain state channel manager. The matching engine provides speed by processing trades off the blockchain, but it will never update a user’s balances unless they have signed orders.

Of course, the matching engine must also interact with the blockchains supported by Nash. This is where our blockchain engineering team comes in: smart contracts store user funds for trading and can interact with both the matching engine and users’ personal wallets.

Manual withdrawal from our contracts is possible at all times, even if the Nash platform and matching engine are unavailable. Users have the option of interacting directly with our smart contracts to withdraw funds. Nash can potentially block trades on the matching engine, but since we do not have users’ private keys, we cannot issue trades or interact with smart contracts on their behalf. Furthermore, the matching engine cannot be exploited to steal user funds from our smart contracts. Even if the matching engine were somehow compromised, user balances would remain untouched.

The matching engine itself is a complex, modular system, but our smart contracts are designed to be simple and portable. This means we can easily adapt them to chains with differing VM runtimes, such as EOS and Cardano. By taking this approach, we ensure that Nash will be able to add new chains as fast as possible. What’s more, when the matching engine becomes fully decentralized, no changes to our smart contract design will be necessary.

At launch, Nash will support both the Ethereum and NEO blockchains. Our smart contracts for these platforms have now been finalized and approved for deployment! This video shows both contracts passing a variety of tests:

The tests for ETH and NEO start out by deploying our exchange smart contracts onto a development chain and creating a few sample NEP-5 and ERC-20 tokens for trading. In the video, you can see the following and more:

After whitelisting a set of assets and users, a number of tests are run to verify that deposits of any type of token are processed in the proper manner.

Important tests then verify that syncing balances between the matching engine and the exchange smart contracts works as expected. These also prove that both a user and the matching engine must sign requests, ensuring we remain fully non-custodial.

For all operations on the contracts, we simulate possible malicious behavior to make sure that they act properly when extra bytes, extremely large numbers or other unexpected parameters are passed in.

A final set of tests verifies the withdrawal of assets from the exchange contract to the user and checks that all balances for the user and the contract are as expected.

While the tests in the video play an important role in ensuring that our contracts operate as they should in a simulated blockchain environment, they are only one small part of our testing infrastructure aimed at guaranteeing the safety of users’ funds.

We are already working on second-layer strategies to incorporate chains not capable of smart contracts, in particular Bitcoin. These solutions should be in place shortly after the launch of our MVP. As with smart contract–capable chains, systems developed for Bitcoin will be adaptable for related technologies, such as Litecoin.

Centralized exchanges do not have to build sophisticated integration systems of this kind. They are not concerned with issues of custody and are happy controlling users’ assets. By developing fully non-custodial, decentralized solutions, Nash aims to bring decentralized finance to everyone with no compromises on security.

Nash will be unveiling our new website and exchange launch program at NEO DevCon in Seattle on 17 February. Keep watching @nashsocial for more updates!