Posts

A multisig transaction example using Algo and an Algorand wallet

A Multisig Transaction Example: 5 Steps to Sending Algo Securely with an Algorand Multisig Account

Multisig transactions are a great deal more secure than single-key transactions, and for good reason: you’re removing a single point of failure, and distributing signing responsibility to a greater number of keys. However, this can add a great deal of effort to the transaction process when it comes time to send your funds to another account.

In this article, I’ll walk you through an offline multisig transaction example using an existing Algorand account (follow the steps in this article if you have not already created an account). While this example shows you how to spend funds, the same steps will apply to registering a participation key, bidding on auctions, and (in the future) voting.

To begin, let’s review all the things we have so far:

  • An online computer with a working Algorand node installation.
  • An “Ubuntu” bootable USB drive, which can be used for an offline computer.
  • A “Keys” USB drive with algokey and a file with the keys for our multisig account
  • A “Transfer” USB drive for transferring files between the online and offline computers

We will use these components to securely send a transaction from our multisig account while keeping our spending keys totally offline. The process will be:

  1. Create an unsigned transaction on the online computer
  2. Move this transaction file to the offline computer
  3. Sign the transaction on the offline computer
  4. Move the signed transaction back to the online computer
  5. Send it to the network

1. Prep Spend Transaction and Save Out to tx File (Online)

The process starts on the online computer. We will prepare an unsigned transaction file that describes the transaction we want to execute. Our transaction will be to send 1 Algo from the multisig account we created in this post to a destination account with address: 5DJNGUEXNRUKAQODHGO3KS2HXOHN4YMSLSZQGEAH5L3WMMDFKMZEQMURUY.

Open a terminal on the online computer and issue the goal node status command:

purestake@algo-node:~$ goal node status
Last committed block: 1630913
Time since last block: 2.7s
Sync Time: 0.0s
Last consensus protocol: https://github.com/algorandfoundation/specs/tree/5615adc36bad610c7f165fa2967f4ecfa75125f0
Next consensus protocol: https://github.com/algorandfoundation/specs/tree/5615adc36bad610c7f165fa2967f4ecfa75125f0
Round for next consensus protocol: 1630914
Next consensus protocol supported: true
Genesis ID: mainnet-v1.0
Genesis hash: wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=
purestake@algo-node:~$

The goal node status command returns information about the node and its view of the blockchain. Make a note of the “Last commited block” value, which we will need when we construct our transaction file. The reason is that transaction files are only valid for up to 1000 rounds or blocks. So we need to specify a validity range with the last commited block as the starting value for the range. The goal clerk send command can be used to create the transaction file:

purestake@algo-node:~$ goal clerk send -a 1000000 -f FHYPIFKSTJTUT4QCR4MJWZUY2Y4URVFHF2HIXGZ4OHEZSIEQ5Q64IIGEMY -t 5DJNGUEXNRUKAQODHGO3KS2HXOHN4YMSLSZQGEAH5L3WMMDFKMZEQMURUY --firstvalid 1630913 --lastvalid 1631912 -o transaction.tx
Please enter the password for wallet 'MyWallet':
purestake@algo-node:~$

The goal clerk command above creates a file called transaction.tx in the working directory with an unsigned transaction that will send 1 Algo from FHYPIFKSTJTUT4QCR4MJWZUY2Y4URVFHF2HIXGZ4OHEZSIEQ5Q64IIGEMY to 5DJNGUEXNRUKAQODHGO3KS2HXOHN4YMSLSZQGEAH5L3WMMDFKMZEQMURUY with a validity range of block 1630913 to 1631912.

Note that the amount is specified in microalgo as 1000000. All the algorand command line tools generally take Algo amounts in microalgo, or millionths of an Algo. Be very careful when specifying amounts as arguments to these commands. Without commas to create visual separation, it is very easy to make a mistake with an extra or missing zero.

I used the previously-recorded block height value of 1630913 as the firstvalid argument. To come up with the lastvalid argument value I added 999 to the firstvalid value. Generated transactions can have a maximum validity of 1000 blocks. Blocks are being finalized every ~4.5 sec currently, so this means that the transaction file will be valid for roughly 75 min. This can make timing tricky, depending on the coordination needed to actually sign the transaction. However, you can specify validity ranges out into the future if you need more time to perform the signing action.

Inspect tx file (online)

It is always a good practice to check the transaction file for correctness before proceeding to subsequent steps. The file is a binary file so opening it in a text editor is not useful. But we can use the “goal clerk inspect” command to look at its contents. To inspect the file contents, run the following command:

purestake@algo-node:~$ goal clerk inspect transaction.tx
transaction.tx[0]
{
"msig": {
"subsig": [
{
"pk": "OBONCJ4D4WEUYFWRDLZEJOMAN22HWZGZPAEWSPK7S6VOIHDCAFR3ACUSTA"
},
{
"pk": "P7ZEFUIWTABXLMC77P3DAE5ZMU7BDY3HZ4KF7ZXSPTCYKZ4AOCKGRZTCUE"
},
{
"pk": "JPPERBQVBGKHMKTVZUOQKSZHVDYMC3AYYD6NHT355HEZHZXW5CLNUIMJT4"
},
{
"pk": "GW5J5C2X7L7F2NIWISELS5EQI74Y5W6VDZ2W45NLIYY256EUYLKORY7AJE"
},
{
"pk": "ANQADWSXUDMOHYYOVAKII3COO3KIBBXXLFF2RPSCFIVXQJZOZ76DKR5YPU"
}
],
"thr": 3,
"v": 1
},
"txn": {
"amt": 1000000,
"fee": 1000,
"fv": 1630913,
"gen": "mainnet-v1.0",
"gh": "wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=",
"lv": 1631912,
"note": "y0+1BZ82wxY=",
"rcv": "5DJNGUEXNRUKAQODHGO3KS2HXOHN4YMSLSZQGEAH5L3WMMDFKMZEQMURUY",
"snd": "FHYPIFKSTJTUT4QCR4MJWZUY2Y4URVFHF2HIXGZ4OHEZSIEQ5Q64IIGEMY",
"type": "pay"
}
}

purestake@algo-node:~$

The first section shows that this is a transaction from a multisig account, and the 5 public keys for the multisig account are present. In the bottom section, you can find details about the transaction that we specified on the command line, such as the amount, firstvalid, lastvalid, the destination address, etc. The fee value is the fee for sending the transaction, which currently defaults to 1000 microalgo.

2. Copy tx File to the Air-gapped Machine

The transaction file transaction.tx is ready to be signed. But recall that we don’t have the spending keys on this online computer. The spending keys are on a USB device and will be used for signing on the offline computer. The unsigned transaction file cannot be used to send funds without being signed with 3 of the 5 spending keys associated with the multisig account, so it is reasonably safe to copy this file.

Copy transaction.tx to the “Transfer” USB drive.

As a next step, reboot the computer using the Ubuntu USB drive into an offline state and plug in the Transfer and Keys USB drives.

3. Sign tx File on the Air-gapped Machine (Offline)

Once we are booted to the offline Ubuntu desktop, we will perform the signing action for the transactions. We will create a folder on the Ubuntu desktop called tx and copy into it the algokey, the text file containing the keys, and transaction.tx. To sign transaction.tx, open a terminal to the tx folder on the desktop and issue the algokey multisig command to sign the transaction file:

ubuntu@ubuntu:~/Desktop/tx$ ./algokey multisig -t transaction.tx -o transaction1.tx.signed -m "expire wear husband fancy now until laundry token strong dignity arrow valley post raven pudding farm twin chalk cloud tenant cart off shop abandon trophy"
ubuntu@ubuntu:~/Desktop/tx$ ./algokey multisig -t transaction.tx -o transaction2.tx.signed -m "lucky dust hub crew barely leave gas crew canvas exhibit margin mixed impose air wasp chat athlete sketch ozone humble parent rail remind abandon host"
ubuntu@ubuntu:~/Desktop/tx$ ./algokey multisig -t transaction.tx -o transaction3.tx.signed -m "draft mule stamp run absent congress leopard notice minute hungry fresh physical flee favorite cram green salad promote remember route assume gentle early absorb during"

These 3 algokey multisig commands each perform a private key signing action on the provided transaction.tx that we created in a previous step, as outlined in this blog post. The private key is supplied on the command line as a mnemonic, and each invocation creates a different signed transaction output file, transaction1.tx.signed, transaction2.tx.signed, and transaction3.tx.signed.

4. Move tx Files Back From the Air-Gapped Machine

With the signed transaction files in hand, copy transaction1.tx.signed, transaction2.tx.signed, and transaction3.tx.signed to the Transfer USB, remove the Ubuntu bootable USB and the Keys USB, and reboot the computer back to its regular online mode. Once it is booted, log in and copy the 3 signed transaction files from the Transfer USB to a directory on the computer. In my case, I just put the files in my user’s home directory.

Merge the Signatures Back to a Single tx File

We can inspect one of the signed transaction files using the same goal clerk inspect command that we used before to inspect the unsigned transaction.tx file. Issue the following command:

purestake@algo-node:~$ goal clerk inspect transaction1.tx.signed
transaction1.tx.signed[0]
{
"msig": {
"subsig": [
{
"pk": "OBONCJ4D4WEUYFWRDLZEJOMAN22HWZGZPAEWSPK7S6VOIHDCAFR3ACUSTA",
"s": "M7dVRrm9zmcE0dLkZTMX7JTjk/tsZdIgLn0qQuL9sGDDCnPZfiKRE9kpBYpSyfZ9uWvtCijJzJIInIbtNijRBg=="
},
{
"pk": "P7ZEFUIWTABXLMC77P3DAE5ZMU7BDY3HZ4KF7ZXSPTCYKZ4AOCKGRZTCUE"
},
{
"pk": "JPPERBQVBGKHMKTVZUOQKSZHVDYMC3AYYD6NHT355HEZHZXW5CLNUIMJT4"
},
{
"pk": "GW5J5C2X7L7F2NIWISELS5EQI74Y5W6VDZ2W45NLIYY256EUYLKORY7AJE"
},
{
"pk": "ANQADWSXUDMOHYYOVAKII3COO3KIBBXXLFF2RPSCFIVXQJZOZ76DKR5YPU"
}
],
"thr": 3,
"v": 1
},
"txn": {
"amt": 1000000,
"fee": 1000,
"fv": 1630913,
"gen": "mainnet-v1.0",
"gh": "wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=",
"lv": 1631912,
"note": "y0+1BZ82wxY=",
"rcv": "5DJNGUEXNRUKAQODHGO3KS2HXOHN4YMSLSZQGEAH5L3WMMDFKMZEQMURUY",
"snd": "FHYPIFKSTJTUT4QCR4MJWZUY2Y4URVFHF2HIXGZ4OHEZSIEQ5Q64IIGEMY",
"type": "pay"
}
}

This looks very similar to the unsigned transaction.tx that we inspected before, but note that the first public key (pk) in the top section now has an “s” value. This “s” value is the signature that was created using the private key for that address. It is not the private key itself, but it demonstrates that we had knowledge of the private key. The other 2 files look similar, but have an “s” value for public keys 2 and 3. What we need to do is merge all of these signatures into the same transaction file which we will call transaction.tx.signed. We can do this using the goal clerk multisig merge command like this:

purestake@algo-node:~$ goal clerk multisig merge -o transaction.tx.signed transaction1.tx.signed transaction2.tx.signed transaction3.tx.signed
purestake@algo-node:~$

We now have a merged signed transaction file called transaction.tx.signed in the working directory.

Inspect tx File Before Sending (Online)

Now let’s inspect the resulting merged transaction.tx.signed file:

purestake@algo-node:~$ goal clerk inspect transaction.tx.signed
transaction.tx.signed[0]
{
"msig": {
"subsig": [
{
"pk": "OBONCJ4D4WEUYFWRDLZEJOMAN22HWZGZPAEWSPK7S6VOIHDCAFR3ACUSTA",
"s": "M7dVRrm9zmcE0dLkZTMX7JTjk/tsZdIgLn0qQuL9sGDDCnPZfiKRE9kpBYpSyfZ9uWvtCijJzJIInIbtNijRBg=="
},
{
"pk": "P7ZEFUIWTABXLMC77P3DAE5ZMU7BDY3HZ4KF7ZXSPTCYKZ4AOCKGRZTCUE",
"s": "rjITXvqzQwFWZ5shfXjhkxpcAkPSJquv9s2gLACLljHKnaoYefTGUXjfKZHtGZixFIAGPWr22DMrk/rcdnf8CA=="
},
{
"pk": "JPPERBQVBGKHMKTVZUOQKSZHVDYMC3AYYD6NHT355HEZHZXW5CLNUIMJT4",
"s": "w08AQ3gJr9W8qVmV1HN4o7okFjU/ozWIHGs3kn4cWjRkx/j1xO3wv+bL5X7fFjt208zaFuacE0y6jKIIc2p3DQ=="
},
{
"pk": "GW5J5C2X7L7F2NIWISELS5EQI74Y5W6VDZ2W45NLIYY256EUYLKORY7AJE"
},
{
"pk": "ANQADWSXUDMOHYYOVAKII3COO3KIBBXXLFF2RPSCFIVXQJZOZ76DKR5YPU"
}
],
"thr": 3,
"v": 1
},
"txn": {
"amt": 1000000,
"fee": 1000,
"fv": 1630913,
"gen": "mainnet-v1.0",
"gh": "wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=",
"lv": 1631912,
"note": "y0+1BZ82wxY=",
"rcv": "5DJNGUEXNRUKAQODHGO3KS2HXOHN4YMSLSZQGEAH5L3WMMDFKMZEQMURUY",
"snd": "FHYPIFKSTJTUT4QCR4MJWZUY2Y4URVFHF2HIXGZ4OHEZSIEQ5Q64IIGEMY",
"type": "pay"
}
}

You can see that the first three public keys all have “s” value signatures. We only need signatures for the first three public keys because this is a 3-of-5 multisig and three valid signatures meets the threshold for the account. If we had signed with a fourth or fifth key, this wouldn’t cause any problems, but it isn’t necessary. This transaction is ready to be broadcast to the network.

5. Broadcast tx to the Network (Online)

To broadcast the signed transaction to the network we can use the goal clerk rawsend command:

purestake@algo-node:~$ goal clerk rawsend -f transaction.tx.signed
Raw transaction ID AAG34CUUNSMZJNNRKYV22UNOPFBQB57XPWNEF6D4CGSOT7ZRPSEB issued
Transaction AAG34CUUNSMZJNNRKYV22UNOPFBQB57XPWNEF6D4CGSOT7ZRPSEB still pending as of round 1631216
Transaction AAG34CUUNSMZJNNRKYV22UNOPFBQB57XPWNEF6D4CGSOT7ZRPSEB committed in round 1631218
purestake@algo-node:~$

The transaction id for your transaction will be unique and different than what you see above. Algorand finalizes blocks in under 5 seconds, so you shouldn’t have to wait long for the transaction to broadcast to the network. Once committed, you can check account balances to make sure you see the balance change that is expected. Once used, the transaction file cannot be used again. Sending it again will result in an error.

Conclusion: More Complex, But More Secure, Too

This multisig transaction example shows that the setup of a multisig account and execution of a transaction are a lot more complicated than just using a single spending key account directly on an online computer with an Algorand node installation. But, by using a multisig account, we can substantially improve the security of the setup and greatly reduced the risk of the private keys and thus the funds in the account from being compromised.

The Algorand multisig features can be used to create multiple keys which can be used to split the secrets needed to spend funds across different people and locations. The exact number, locations, storage, and people will vary according to the environment and situation, but it opens the door for a much more secure setup than a single key account.

Keeping the spending keys totally offline is another substantial improvement to Algorand account security for high-value accounts. Most of the attack vectors for compromising keys involve online scenarios, malware, or other network exploits. By never having the secrets on an online computer, the risk of key compromise is greatly reduced. Another way to improve the security of an Algorand account is to use a ledger hardware wallet, which will be the subject of a future blog post.