IOTA Tutorial 7 | Proof of Work, Curl and Nonce
Proof of Work, Curl and Nonce
In this video series different topics will be explained which will help you to understand IOTA.
It is recommended to watch each video sequentially as I may refer to certain IOTA topics explained earlier.
Making a transaction
- Step 1. Constructing the bundle and signing the transaction inputs with your private keys.
IOTA uses a bundle which consists of multiple transactions containing credits to the receiving addresses and debits from the spending addresses. In IOTA there are two types of transactions: one where you transfer value and thus, have to sign inputs, and ones where you simply send a transaction to an address with no value transfer (e.g. a message). A transaction is an object containing several fields such as an address, signature, value and tag.
- Step 2. Tip selection
The tip selection is a process whereby you traverse the tangle in a random walk to randomly chose two transactions which will be validated by your transaction. Your transaction checks for example if the descendants of that transaction is valid. If these transactions are valid they will be added to your bundle construct.
- Step 3. Proof of Work (PoW)
Once the bundle is constructed, signed and the tips are added to the bundle, the PoW has to be done for each transaction in the bundle. Every transaction in a bundle requires a nonce (this is the result of the PoW) in order to be accepted by the tangle network. IOTA’s PoW is directly comparable to Hashcash, as it serves a similar purpose to prevent spam, and in IOTA’s case, also to prevent sybil-attacks. When the PoW is done, the nonce of the transaction object should be updated. The transaction can now be broadcasted to the tangle network and wait for it to be approved by someone else.
The IOTA light wallet uses the Curl hash algorithm for PoW. There are two methods to execute the Curl hash algorithm:
- Method 1: Using Webgl 2 Curl implemention.
- Method 2: Using CCurl implementation.
CCurl means C port of the Curl library, which uses the system Central Processing Unit (CPU) (aka native route).
PoW is executed faster using GPUs instead of CPUs. By default the IOTA light wallet uses the “Webgl 2 Curl” implementation thereby speeding up the PoW. However, some people will find that they get an “Invalid Transaction Hash” when they use this setting. In that case select the light wallet option “CCurl implementation”.
As mentioned earlier the purpose of the PoW is to prevent spam and sybil-attacks. PoW means calculating the nonce for every transaction in a bundle. When making a value or non value transaction you pay no fee.
However there is a small cost you are paying. You pay for the electrical energy that you spend for the PoW.
The Minimum Weight Magnitude is the difficulty of PoW. An IOTA transaction data is encoded and stored in a string of 2673 trytes (= transactionObjectTrytes). The last 81 trytes of the transactionObjectTrytes is reserved for the nonce.
Execute the PoW using the transactionObjectTrytes and Minimum Weight Magnitude as input.
The PoW outputs the nonce which is 81 trytes in size.
Insert the nonce in the transactionObjectTrytes (= transactionObjectWithNonceTrytes). Convert transactionObjectWithNonceTrytes into trits (= transactionObjectWithNonceTrits) Create and initialise a CheckHash object. This object will hold the Curl hash algorithm result. Create and initialise a CurlHash object.
This object will:
- receive inputs (absorb the transactionObjectWithNonceTrits)
- execute the Curl hash algorithm
- outputs the result (squeeze data into the CheckHash object)
The CheckHash object will hold the Curl hash algorithm result in trits. The number of 0’s at the end of the CheckHash value must be at least the Minimum Weight Magnitude. If that is the case the nonce is valid.
A valid nonce is required for the transaction to be accepted by the tangle network.