Building a Blockchain with Go - Part 6 - Adding Digital Signatures

in #utopian-io6 years ago

golang.jpg

Repository

https://github.com/golang/go

What Will I Learn?

  • You will learn how to Lock Transactions
  • You will learn about Signatures
  • You will learn how to Verify Digital Signatures
  • You will learn how to use ECDSA
  • You will learn about Serializing, Hashing and Regenerating Transactions and Addresses
  • You will learn how to use the String Method in Go

Requirements

System Requirements:

Operating System:

  • FreeBSD 10.3 or later
  • Linux 2.6.23 or later with glibc
  • macOS 10.10 or later
  • Windows 7, Server 2008R2 or later

Required Knowledge

  • A little understanding of the Go programming language
  • Go installed on your computer
  • A text editor or IDE like Gogland (VS Code used)

Resources for Go and this Project:

Credits/Sources:

Difficulty

  • Advanced

Description

Thus far in this Tutorial Series, most of the core blockchain features have been added to this example blockchain. With the wallet module now fully functional, it is possible to modify the transaction system to appropriately lock, verify and sign the data. This includes working backwards from an address to a public hash key and a checksum and then using those pieces to manipulate the wallets and the transactions.

Implementing Digital Signatures

All transactions must be signed in a blockchain. In Cryptography, a Digital Signature is a concept that guarantees core behavior of the blockchain:

  • The Signed Data can't be modified while it is being transferred from one address to another.
  • The sender of a transaction is the one who created that transaction.
  • Data sent by an address can not be denied by the user who sent the data.

The digital signature is derived from the private key of an account and verified with the public key of that account. The signature itself is stored in the Transaction Inputs and can be verified through the Outputs.

tx.png

This image details a flowchart of the current format of transactions and blocks in the blockchain. In this chart, User A mines the Genesis block and obtains a reward of 100 tokens. User A then sends 10 tokens to User B in Block 1. When User A creates the initial transaction, the input in Block 1 references the Output from the Genesis Block. This Input contains the public key of User A and a signature for the entire Transaction. The Blockchain verifies that the Input matches the hash of the referenced Output from the Genesis block. This is the mechanism that allows a user to spend tokens that are allocated to them.

Verification and Recreation of Hashes

The Verification process uses this idea of recreation and redundancy. To verify an address, the blockchain decodes the address using a base58 decoder algorithm and then splits the bytes of the resulting hash into pieces. Each of those pieces are used to rebuild the checksum of the address. This original checksum can then be compared with the new checksum to verify that the address is real. The same is true for a Transaction. When a signature is made, it is derived from two numbers which are concatenated and stored in an Input. The numbers can be split and then regenerated through an ecdsaalgorithm to verify that the transaction is real. Along with these two numbers is the public key of the user who created the transaction. Public keys are made up of two coordinate numbers on an elliptic curve and they also can be split and verified using an ecdsa algorithm.

address.png

Above is an image that contains an Address, the Address's full hash and that full hash split into the Version Hash, the Pub Key Hash and the checksum. Each of these components are combined to create the address and also can be used to re-build the checksum for verification.

verify.png

Here is the code which is used to verify a transaction. The variables R and S are variables which are derived from the signature of the address. These two numbers are originally a part of an elliptic curve algorithm. The X and Y values are the two halves of the Public Key and can similarly be split into separate pieces. On the final line, a new elliptic curve is used along with the x and y values from the transaction digital signature to regenerate and rebuild the public key. This public key is then used with R, S and Hashed Transaction Data to verify the Transaction Data.

The Source Code for this video may be found here: https://github.com/tensor-programming/golang-blockchain/tree/part_6

Video Tutorial

Curriculum

Proof of Work Done

https://github.com/tensor-programming

Sort:  

Hello @tensor

Thank you for doing this series of tutorials.

I am sure many people are fascinated by these tutorials on building a blockchain with Go.

Again, your presentation in the lectures are well done, delivery is pleasant, and very easy for learners to follow.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

As always, thank you for moderating my contribution. There is a small portion of my subs who are fairly dedicated to this series. Its gratifying to see them ask me for more.

Thank you for your review, @rosatravels! Keep up the good work!

Hi, @tensor!

You just got a 5.34% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

Hi @tensor!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @tensor!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!





This post has been voted on by the SteemSTEM curation team and voting trail in collaboration with @curie.

If you appreciate the work we are doing then consider voting both projects for witness by selecting stem.witness and curie!

For additional information please join us on the SteemSTEM discord and to get to know the rest of the community!

Coin Marketplace

STEEM 0.18
TRX 0.13
JST 0.028
BTC 58484.86
ETH 3100.06
USDT 1.00
SBD 2.40