To deploy or not to deploy: Verification contracts on NEO

Igor Machado
NeoResearch
Published in
4 min readNov 4, 2018

Blockchain world is usually surrounded by different interests on cryptocurrencies, digital identities and smart contracts. Digital assets and token exchange is the powerful engine that drives cryptoeconomy, so it’s essential for an efficient blockchain to provide easy, fast and cheap trading. This is one of the most interesting points in NEO open-source blockchain, its capability of performing fast trades for free, showing a great potential for Over-The-Counter (OTC) transactions.

The logic can be implemented in two different levels on NEO. The most popular feature on Neo is to create distributed Applications using NeoContract programming (on C#, Python, Go, Java, …). But, from a smart transaction perspective, if the objective is to perform fast exchanges and Verify that transactions are correct (no double spending, requiring multiple independent signatures, …), Verification Contracts are capable of doing that.

These Verifications are usually free of charge, and usually consist of performing a transaction with an attached Script (sorry, this is where things get more technical…). This Script (written in NeoVM) controls the logic of who will be able to spend the transaction and how. In recent articles we discussed some of Verification capabilities, but now we will go a little deeper, so these are some good references if you think it’s necessary for further reading:

Let’s continue :)

Deploy or not to deploy

Distributed Applications on NEO need to be deployed on the network in order to store data on the blockchain space (called Storage). So when this process is performed, the Script (binary instructions) of the Application will be stored on the blockchain. After that, the Application will be accessible by a sequence of 20 bytes called ScriptHash. The price for deploying a contract on NEO is usually 490 GAS (varies a little more or less depending on features included), so people usually think twice before deploying several contracts (spoiler alert — this price is going down on NEO 3.0!).

Verification contracts, on the other hand, don’t need to be deployed (so no fees are necessary!), you just need to attach one Verification Script to your transaction and that’s it, you got a smart transaction. What few people know is that you can also deploy Verification contracts on NEO… but why would you pay for something you get for free?

Recently, as NEO network has grown, the community has been suggesting many strategies to avoid network spamming while keeping the network free of charge (on many scenarios). One of the strategies is to charge for huge transactions (several bytes), as usual transactions are quite short. The size of your transaction depends on how much logic you put on your Verification Script, and there are some scenarios where this logic can become amazingly complex!

WARNING: This is a very experimental suggestion, but here you are, at NeoResearch crazy channel :)

So, if Verification Contracts get too big, it could possibly become cheaper to pay deploy costs, in order to reduce (to a 20-byte ScriptHash size) all future transaction sizes (and possibly having no extra costs).

Hands-on: deploying a simple user account

Now we get very technical, let’s open our amazing online tool: https://neocompiler.io

The standard user account for tests is Address AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y, which represents Verification Script 21031a6c6fbbdf02ca351745fa86b9ba5a9452d785ac4f7fc2b7548ca2a46c4fcf4aac (and as you already know by now, corresponds to little-endian ScriptHash 23ba2703c53263e8d6e522dc32203339dcd8eee9).

So, if you open Transaction Build tab, and paste your Verification Script, you will be able to transfer funds to another address (see Figure 1)

Figure 1 — Usual transaction build process to transfer funds from Verification Contract

We have covered this feature in previous posts, so now we will propose something different… let’s deploy our user account! (Hopefully, this is a shared privatenet for test purposes, which can give you infinite funds every 12 hours).

After deploying our Verification Contract 21031a6c6fbbdf02ca351745fa86b9ba5a9452d785ac4f7fc2b7548ca2a46c4, we go back to Transaction Build and insert our Verification Script to create a transaction. Before signing this transaction, let’s include a special feature called Script Transaction Attribute (or attribute code 0x20). This attribute indicates that we will process a given Script in this smart transaction, identified by its ScriptHash. So, we will use our deployed account ScriptHash together with code 0x20 on Attributes field: 2023ba2703c53263e8d6e522dc32203339dcd8eee9.

Now, you can sign and generate the transaction. But, before submitting, let’s do a last manual handcrafting… the Transaction Build tool will naturally include the Verification Script (but we don’t want that, because we want to keep it shorter now), so we just remove the Verification Script from the end of the transaction. In our case, transaction was ending with bytes …2321031a6c6fbbdf02ca351745fa86b9ba5a9452d785ac4f7fc2b7548ca2a46c4fcf4aac, so we replaced this last part (including 23) with 00 (which means we are attaching an empty Verification Script). Ok, transaction submitted and accepted :)

Figure 2 — Contract Transaction that automatically gets Verification Script from deployed contract

So, here it goes (images from neoscan on privatenet):

Transfer of 10 NEO on privatenet without attaching Verification Script
No Verification Script is attached, only a Script reference to the deployed contract

Example Transactions

If you want to dig more in both transaction formats, these are the ones I used:

(1) Using Verification Script

80000120e9eed8dc39332032dc22e5d6e86332c50327ba230100d3f1e14eb1d62e4fad7610049726a11337059782890d327a9f0a9a5a6d8eea0100029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc5002f68590000000052eaab8b2aab608902c651912db34de36e7a2b0f9b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc5004b1d75f086230023ba2703c53263e8d6e522dc32203339dcd8eee9014140f79b6c28b0a9fdb953071e78fe78caebc687efb23e0008ee1d1fc1c03e1d2a34a4731c3550baa7c791c2335262df38706534f5c56b6b4bcaf2a11d55efac12ba2321031a6c6fbbdf02ca351745fa86b9ba5a9452d785ac4f7fc2b7548ca2a46c4fcf4aac

(2) Without Verification Script (deployed contract)

8000012023ba2703c53263e8d6e522dc32203339dcd8eee90161dd84af1263ad853a38ebf5b329777e306f2f5a184830f6a156cae986ca4be10100029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500ca9a3b0000000052eaab8b2aab608902c651912db34de36e7a2b0f9b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc5005c6bade586230023ba2703c53263e8d6e522dc32203339dcd8eee90141405ce0fefbee0eb6cddc1576edc3eabecc411d7ee52f6c853436b938abed115b7232e2e8c013030f961d8985b3d4b5fd1bc52e75b6594882e9b154724209ce2f6a00

Have fun!

--

--