NEXA — NexScript Multiplex Contracts

Nexa community!

Another week, another NexScript upgrade. Otoplo is paving the way to make NexScript one of the easiest coding languages to build high-quality smart contracts.

The current upgrade allows the construction of arbitrary relationships between UTXOs, enabling you to pre-define a complex sequence of interactions between any number of contracts, all from a single document.

Basically it overcomes the limitation of UTXO smart-contracts being ‘single-use’ only and instead turns them into dynamic entities that can persist through multiple UTXOs.

What are multiplex contracts?

MAST are the first building block for what Paul’s Otoplo calls: Mutliplex Contract Paths. MCPs allow MAST technology to be combined with advanced covenants so that multi-UTXO smart-contract architectures can be built from within a single NexScript contract file. We call these advance contract architectures ‘Multiplex Contracts”.

This brings NexScript smart-contract capabilities to be much closer to what is found in Solidity and EVMs, but in a form that is orders of magnitude more efficient for scalability.

Multiplex contracts are collections of contracts with complex relationships. NexScript now allows the outputs of contracts to be locked to other contracts defined in the document via new ‘Accessor’ functions. These can access the following properties of other contracts: template bytecode, templateHash, constraintHash, visibleParams and lockingBytecode.

Check out the example contract code below. What you can see is that there are multiple contracts within a single document, and that one contract can lock its output to the code of another contract. This can be done with an unlimited amount of contracts.

pragma nexscript ^0.7.0;
contract A() {
function A(string vA, int x) {
bytes lockingBytecode = B.lockingBytecode;
require(tx.lockingBytecode == lockingBytecode);
require(vA == "A");
require(x == 1);
}
function B(string vA, int x) {
require(vA == "B");
require(x == 2);
}
}
contract B() {
function Bv(string vB) {
require(vB == "B");
}
}
contract C() {
function Cv(string vC) {
bytes20 hash = A.templateHash;
require(hash.length != 0);
require(vC == "C");
}
}

So we have the MAST architecture that enables a much larger number of different contract functions to be built and executed (as long as the section of script that is being executed fits within the network limits), and we have Covenants which allow smart-contracts to constrain their offspring.

It’s possible to build smart-contacts that are constrained to MASTs and that those MAST scripts constrain the outputs with covenants and that those covenant scripts can also be MASTs ad infinitum.

Check out the code below. The MAST contract ‘MCP’ contains multiple contracts inside it and the contract ‘McpCovenant’ then locks its own output to this MAST contract. Contracts in contracts in contracts!

pragma nexscript ^0.7.0;
// Define an MCP contract
contract MCP() {
contract MastA() {
function constraint(string vA, int x) {
require(vA == "A");
require(x == 1);
require(tx.outputs[0].lockingBytecode = A.lockingBytecode);
}
}
contract MastB() {
function constraint() {
require(tx.outputs[0].lockingBytecode = B.lockingBytecode);
}
}
}
contract McpCovenant() {
function covenantConstraint() {
require(tx.outputs[0].lockingBytecode = MCP.lockingBytecode);
}
}

What do Multiplex Contracts enable?

Unlocking the Future of UTXO Smart-contracts

Everything. The Multiplex smart-contract architecture enables essentially limitless programmability. Well, almost. But we are pretty sure this architecture makes Nexa functionally ‘Turing Complete’. An individual transaction cannot be turing complete of course, but we are quite sure that an Multiplex contract can be, as loops can be achieve through multiple transactions.

DeFi on NEXA with Multiplex Contracts

The Multiplex architecture will allow developers to compress any level of smart contract complexity into a UTXO-based smart contract.

It enables features such as:

  • DAO’s in the most complex form,
  • DeFi as known from other chains like ETH or SOL,
  • Constant Product Market Makers (Also known as a DEX, for example, Uniswap),
  • Stablecoins through entities like MakerDAO and even algorithmic stablescoins are possible,
  • And much more.

Developers can write a contract that offers not only almost endless optionality for the contract executed in a single UTXO, but also the ability for a smart contract to constrain all its offspring UTXOs with any other contract. A contract can now be constructed with code paths of limitless complexity.

So basically, anything in the Decentralized Finance world that you’re familiar with from EVM-like programmability is possible. However, there’s a significant difference: it’s native to Nexa, offering both fast speed and scalability, all while maintaining incredibly low fees.

Useful links:

--

--

Nexa: Seamless scalability, endless opportunities.

Nexa is an open source network with a public distributed ledger. Next generation store of value with instant transactions, smart contracts and tokens.