text
stringlengths 61
434
|
---|
knowledge that we just learned combined with some other pieces to kind of get this this public here. So I'm not gonna go too deep into it. But we have this private key that we create. And we get this public key. Now this public key we want everybody to have access to right this is yeah, whole world can see this, |
this private key, we really want it to be private, we don't want people to see this, we're going to use this private key as like a password to quote unquote, digitally sign transactions, and then people can verify them with this public key. So let's, let's |
see what this actually looks like. Let's pick a random key, a more secure key, right? Because the longer it is, the more secure it's going to be. And if we go to signatures now, right? Let's say we have this, this message that we want, right? We'll say hi world, right? We want this To be the message, |
what's gonna happen is this private key that we've created, we can use to sign this data, right? Remember how in the blockchain demo, you know, we were kind of we were hashing stuff, right? We were using this Shea 256 hash to get this hash. Well, we're doing something similar. But instead of hashing, |
we're, we're using this digital signature algorithm to create this message signature. Now, what's really powerful about how this this algorithm works, is that you can create this message signature with your private key, but somebody else can't derive |
your private key from the message signature. And that's what makes this really, really powerful. However, if we go to verify using this public key, right, and so this is the this is that, Oh, 403. This is that same public key, using this, using this public key, anybody can verify, let's go ahead and |
sign again, anybody can verify that the signature is yours, right? So you have a public a private key, just for you. So you can sign things and a public key that anybody can verify something, right. So anybody can verify this, and let's say |
somebody tries to fake a transaction from you, they say, Hey, you know, this is this is this is their transaction, all they have to do is verify that this signature against your public key and very easily, this whole thing turns red, because |
it isn't verified, right, that the algorithm says, hey, that's wrong. So we can go ahead and take that into transactions in this exact same way. So if I want to send money, you know, if I want to send $400, from, you know, my address to another |
address, using my private key, I can sign that transaction. And anybody else in the world can then verify this transaction, right. And this is why when people say Hydra keys, you know, protect your keys, this is what we're talking about in our accounts here. Right? If we go to settings, and again, the only |
reason that I'm showing you guys, my pneumonic, and my private key is because this is a, this is a dumpster account, I'm going to throw this away at the end of this video, or I'm just not gonna put any real money in it. But when we look at |
our Metamask, here, we have this pneumonic phrase, which allows us to easily get these different private keys, right? So pneumonic phrase combined with, you know, whatever account number will get us a private key. So mnemonic phrase combined |
with one, we're gonna get this private key. And this is when we look at account details, export private key. That's where it confirm, this is going to be the private key that we're going to use to sign our transactions, right, this, if |
anybody else gets access to this private key, they then can sign transactions for us, and they can send transactions for us. And that's why we want to keep these private, so that it works the exact same way, right. And so this is why it's so important to hide your private keys and hide your mnemonics now, your |
Aetherium address is actually a piece is actually a piece of your public key. Now, to get our address in Aetherium, all we have to do is take this public key that we've created with our private key, hash it using that same Aetherium hashing |
algorithm, and then take the last 20 bytes. And that's how we'll actually derive to our to our address here. Now, knowing the exact methodology of how to get the address doesn't really matter, because it could change blockchain to blockchain and could even change it too. But just know that that is |
essentially how kind of these addresses are derived or there's some derivative of the public key, right, because the public key is public. And you know, using the public key and kind of any public way is totally fine, but not the private key. So that is how we sign our transactions. Note though, this isn't how we |
send the transaction. So so this is just going to assign it create a transaction for us to send, we'll learn later on how to send these transactions. Cool. So that was a lot of information there too. Let's do a quick recap, your public key is derived by using a digital signature algorithm on your |
private key, right, and you want to keep your private key private at all times, because you're going to use your private key to sign transactions. Signing transactions with your private key, you are the only one who can actually do this because you can't get the private key from a message signature. However, |
using your public key, you can anybody can very easily verify that a signature that signed by you is in fact signed by you in our meta mask. Our private keys are located in this account details section you just hit show private keys and type in |
your password. And you'll get your your private key here. A quick note here is oftentimes when using your private keys somewhere, they want it in hexadecimal form. So if we're going to use our private key for something like brownie, which we'll go into later, we need to actually append a 0x to the |
front but We'll get into that later. And the address of your account is derived from this. So if you think about your private key creates your public key, which then can create your address. And there's a little barrier or a big barrier here. |
Because your private key, you want to keep private and your public key and your address can all be public information. Now that we know a little bit more about what's going on underneath the hood of these blockchains, let's go back at our transactions and look at |
this gas thing again, and we'll look to see what's actually happening here, gas in particular can be a little bit tricky to wrap your head around. So if you don't get it right away, don't worry. As we go through examples, it'll start to make more sense. So before I was saying, let's just look at this transaction fee bid, which is the costs associated with |
running this transaction. If I scroll over this on ether scan, I can see this thing that says block base fee per gas plus max party fee per gas times the gas use, which might be a little bit confusing here, let's actually break down what's going on on Aetherium with ERP 15, five nine in place. And again, this is |
going to be specific to Aetherium, as every blockchain might do it a little bit differently. But if we click to see more, we can see a number of useful values here, we can see gas limit is 21,000. And usage is 21,000. So this transaction used 21,000 gas, and we sent 21,000 gas along with it. |
Sometimes when sending a transaction, depending on when it's sent. And depending on what the specific instructions are, it might actually use way more gas than what you want it to use. So with your transactions, you can actually set a limit, hey, I don't want to use more than x amount of gas, I don't |
want to do more than x computational units. And in fact, we go to our Metamask. And we click Send to transfer between accounts again, and we pick you know, 0.01 eath, or something next can actually hit this little button here, go to |
Advanced, and we can actually edit some specifics of this transaction, one of them is going to be the gas limit, we can change this gas limit to maybe 2200 2300, or more or even less, since sending Aetherium takes exactly 21,000 Gas |
Metamask just defaults to setting into that. Well, we also see these other interesting things, we see a priority fee, and a max base fee. Let's reject this transaction. And let's look back at ether scan to talk about these. So currently in Aetherium, according to EE IP 1559, every transaction on |
Aetherium comes with something called the base fee. This is the minimum gas price you need to set to include your transaction. And you'll notice that these are priced in something called gateway. So what is a gateway? If we come to the site eath converter.com. And again, there's a link to this in the |
GitHub repository, we scroll down we can see way gateway and ether five put one ether in here, I can see how much one ether is in terms of way. And in terms of way, one ether is equal to 1-234-567-8990. So that's that's 1 billion way is going to |
be one ether. And then 1-234-567-8910 1112 1314 Did 16 Seven, eight team and then 18 zeros is away. These are just easier ways of referring to really, really small amounts of Aetherium. So if we look at our gas fees, we see that the base |
fee is 0.00000004 Go away. And this obviously would be an even smaller number if this was in units of weigh. So if we take this number, and we put it into our calculator, we can see that |
this is equal to 40 weigh or 0.0000 a whole bunch of zeros for ether. The max fee here refers to the maximum gas fee that we're willing to pay for this transaction. And you can actually see that our max fee is a little bit higher than what we |
actually ended up paying. Our maximum was 2.2132 something something and the gas price we actually paid was up here. Now your transaction might of course be a little bit different than Additionally we have a max priority fee. This is going to be the max gas fee that we're willing to pay plus the max tip |
that we're willing to give to miners. Now currently in Aetherium, this base fee ends up getting burnt and we can see on ether scan exactly how much is getting burnt here. And if we pull up our calculator again, we can grab this gas fee, multiply |
it by the amount of gas we used, and we can see that this is indeed how much Aetherium we actually ended up burning. We go back to Ethereum converter, paste it in we can see that these two numbers are indeed equal. This means whenever you send a transaction, a little bit of Aetherium is removed from |
circulation forever, or it's considered burnt. So currently, in theory As part of your Aetherium part of your transaction fee actually gets burnt. And then the other part goes directly to miners. So to figure out exactly how much went to miners, we could do this number minus the burnt amount. |
And this is how much Etherium was paid to Aetherium miner for this transaction, you'll see down here your transaction type to ERP 15, five, nine, this is the eip 15 five nine version of these transactions. Like I said, every blockchain is going to have a different fee burning and fee and gas process. And they're |
all going to be a little bit different, but the some of it is blockchains have limited block space for transactions, the gas price that costs for your transaction to be included in one of these blocks changes based off how much demand there is the base gas fee for Aetherium will go up and down |
depending on how many people are sending transactions and how many people want to be included in a block. If a ton of people want to be included in a block. That means a ton of gas is obviously going to get burnt. We've left a link to a video in |
the GitHub repository with this section from this YouTuber who does an amazing job breaking down this EIP 15, five, nine and more about how this gas model actually works. I highly recommend you pause this video and watch that video. To understand more, the base fee gets programmatically |
algorithmically adjusted to try to target for all the blocks to be 50% full. If they're more than 50% full, this base fee automatically goes up. If they're less than 50% full, this base fee goes down. Now this is a lot of the basics of how this |
transaction works. And it can be a little confusing. So let's do a quick refresher of everything in here. There's a unique transaction hash that uniquely identifies this transaction. On this blockchain, we can see the status, we can see the block number that it's confirmed on. One other thing we want to look |
at. If we scroll up, we see block number and block confirmations. This is how many blocks have been mined. Since this block was included. Like we saw with our blockchain demo, the longer the blockchain gets, the harder it is to tamper with and the more secure it is typically, you'll see some |
processes say they'll only do something after 20 Block confirmations, 30 Block confirmations or etc. The reason that they wait for these block confirmations is because they want to make sure that that transaction is actually included. And we can actually see the block that our |
transaction was included in and all the other transactions with it, different details about how much gas was used, the gas limit, etc. timestamp is when the transaction happened, we can see from and to we can see the value. And then we can see the |
transaction fee, which we see right here is blocked base fee per gas plus the max priority fee per gas times the gas used. And we see all the details of the gas down here gas price is the cost of one unit of gas gas limit is the max amount of units |
of gas that we're willing to pay in this transaction, the usage is how many actually got us the base fee is going to be the base network fee per gas. So 40 way per one gas used, the max gas is the max gas price we're willing to pay. And Max priority is |
gonna be the max gas price, plus the tip that we give to miners, and then we can see how much is burnt. And then we see transaction savings which which is the difference between how much was actually used or paid for and then returned. So for example, in this transaction, the gas price we ended up |
picking was a little less than our max gas price here. So the gas price we ended up using was a little less than our max priority fee here. So we had some savings compared to that, we can also see that this was an ERP 15 five nine transaction, we can see our nonce here, which was not zero because the |
transaction that I'm showing is our first nones. And then of course, we can see the input data for transactions that are just sending Aetherium, the input data is going to be blank. But you'll see that when we get to smart contracts, the input data is not going to be blank. And it's going to be one of the most important features of these transactions. You'll also notice |
that there's a state tab. This is an advanced tab, and it shows the different states that are changed based off of this transaction. We're going to ignore this one for now. Now that we know how the blockchain itself works under the hood, let's talk about some blockchain fundamentals. And we actually |
covered all these topics in a previous Freako camp video. So let's go to that. If the first time you listen to this, some of these concepts seem a little bit hard to grasp. Don't worry about it. As we continue and as we move on with this course, they'll start to make more sense |
when you see them used in real examples. I definitely would recommend going back and rewatching and re listening to the parts that you don't quite get an asking questions in the discussions tab of the GitHub repository. Awesome. So now that we know all the cryptography pieces and all the little nitty |
gritties of how the blockchain actually works, and how our signatures work and how everything sticks together. Let's talk a little bit about how this works, in actuality, and what's really going on. Now for a lot of this, each different blockchain has slightly different algorithms and slightly different metrics and criteria for doing a lot of |
this stuff. So when we're talking about these specific implementations, keep in mind, the exact algorithm might be a little bit different, but the concepts are all still going to be exactly the same. Hashing and hash function is going to be the same. No matter where you look at decentralized blockchain, |
it's going to be the same no matter where you look, how it's actually implemented, is going to be a little bit different. Now traditionally, when you run an application, you will be website or something that connects to some server, you are interacting with a centralized entity. And unlike how we saw |
with the blockchain with multiple different peers, it's going to be run by a single centralized group. Now, it still could be run on many different servers, but all those servers are still going to be controlled by the same centralized group blockchains, as we saw run on a network of different independent |
nodes. When we saw a peer, a peer, B Piercey. Those were different examples of different independent users running the blockchain technology on their own node. Now, when I use the term node, I'm usually referring to a single instance of a decentralized system. So when I say a single node, when I'm |
talking about a blockchain, I'm talking about one of those pure A's pure BS pure C's running that blockchain software, I'm talking about one server running this technology. And again, it's this network. It's this combination of these nodes interacting with each other, that creates this entire blockchain. What makes these so potent too, is that anybody can |
join the network. And that's why there's decentralized the barrier to entry is a little bit of hardware requirements for getting the correct materials to run the software. And then you running the software, anybody can join these networks and participate. And that's what makes it truly decentralized. In fact, you can go to GitHub right now, and run your own Aetherium |
node in a few seconds. Now in the traditional world, applications are run by centralized entities. And if that entity goes down, or is maliciously bribed, or decides that they want to shut off, they just can't, because they are the ones that control everything. blockchains, by contrast, don't |
have this problem. If one node or one entity that runs several nodes goes down, since there are so many other independent nodes running that it doesn't matter, the blockchain and the system will persist so long as there is at least one node always running. And luckily for us, most of the most popular chains |
like Bitcoin and Aetherium, have 1000s and 1000s of nodes. And as we showed in our demo, if one node acts maliciously, all the other nodes will ignore that node and kick that out or even punish it in some systems, because they can easily check |
everybody else's node and see, okay, this one is out of sync with the majority. And yes, majority rules when it comes to the blockchain. Each blockchain keeps a full list of every transaction and interaction that's happened on that blockchain and we saw if a node tries to act maliciously, then |
all their hashes are going to be way out of whack and they're not going to match everybody else. This gives blockchains this incredibly potent immutability trait where nothing can be changed or corrupted. So in essence, we can think of a blockchain as a decentralized database. And with Aetherium, it has an extra additional feature where it also can do computation |
in a decentralized manner. Now let's talk consensus, proof of work and proof of stake because you've probably heard these before. And they're really important to how these blockchains actually work. We went through that blockchain example, and we did that mining feature. This is what's known as |
proof of work. Proof of Work and proof of steak fall under this umbrella of consensus and consensus is a really important topic when it comes to blockchains. Consensus is defined as the mechanism used to reach an agreement on the state or a single value on the blockchain, especially in a |
decentralized system. I briefly alluded to this consensus mechanism in our blockchain example, when I said if one change is something and the other two, don't, then majority will rule and kick that one out. This is part of that consensus mechanism. Now very roughly a consensus protocol in a |
blockchain or decentralized system can be broken down into two pieces, a chain selection algorithm, and a civil resistance mechanism, that mining piece that we were doing, or where the proof of work algorithm is what's known as a civil resistance mechanism. And this is what Aetherium and |
Bitcoin currently use. Please note that depending on when you're watching this, if eath two is out, then it's no longer proof of work. Now, proof of work is known as a civil resistance mechanism, because it defines a way to figure out who is the block author, which node is going to be the node who did |
the work to find that mine and be the author of that block so all the other nodes can verify that it's accurate civil resistance is a blockchains ability to defend against users creating a large number of pseudo anonymous identities to gain a disproportionately advantageous influence is over |
set system. And in layman's terms, it's basically a way for a blockchain to defend against somebody making a bunch of fake blockchains so that they can get more and more rewards. Now, there are two types of civil resistance mechanisms that we're going to talk about here. Namely proof of work and proof of stake. Let's talk about proof of work a little bit more in depth |
first, in proof of work. This is civil resistant, because a single node has to go through a very computationally expensive process called mining, which we demonstrated earlier to figure out the answer to the blockchains Riddle of finding that correct nonce, or, or whatever the blockchain system has in place. And proof of work. This works |
because no matter how many pseudo anonymous accounts you make, each one still has to undergo this very computationally expensive activity of finding the answer to the proof of work problem, or the proof of work riddle, which again, in our demonstration, it was finding a nonce with that |
first four zeros. But again, each blockchain might change the riddle work or change the problem to be a little bit different. In fact, some of these blockchains make this riddle intentionally hard or intentionally easy to change what's called the block time, the block time is how long it takes between blocks being published. And it's proportional |
to how hard these algorithms are. So these problems actually can change. Depending on how long they want the blockchain to be. If a system wants to block time to be very, very long, they just make the problem very, very hard. If they wanted to be very short, they make the problem a lot easier. We'll talk about |
civil attacks in a little bit and how they can affect the system. But with proof of work, it's a verifiable way to figure out who the block author is and be civil resistant. Now, you need to combine this with a chain selection rule create this consensus. Now, there's some consensus protocols that have more features, but very, very roughly, these are the two |
pieces that we're going to look at. The second piece is going to be a chain selection rule. How do we know which blockchain is actually the real blockchain and the true blockchain now on Bitcoin and Aetherium, they both use a form of consensus called Nakamoto consensus. And this is a combination of proof of work |
and longest chain rule, the decentralized network side that whichever blockchain has the longest chain, or the most number of blocks on it is going to be the chain that they use. This makes a lot of sense, because every additional block that a chain is behind, it's going to take more and more |
computation for it to come up. That's why when we saw in our transaction, we actually saw confirmations. The number of confirmations is the number of additional blocks added on after our transaction went through in a block. So if we see confirmations as to it means that the block that our |
transaction was in has two blocks ahead of it in the longest chain. Now, I do want to point out that a lot of people use proof of work as a consensus protocol. And I do want to say that this is a little bit inaccurate, but sometimes people use it interchangeably. Proof of Work is a piece of the overall |
consensus protocol, which in Bitcoin and Aetherium. One current case is Nakamoto consensus, Nakamoto consensus is a combination of proof of work, and this longest chain rule, both equally and very, very important. Now, proof of work |
also tells us where these transaction fees and these block rewards go to remember how when we made this transaction, we had to talk about gas and a transaction fee. So who's getting paid who was getting this transaction, and this transaction fee is going to the miners or the validators in a |
proof of work network? They're called miners and in the proof of stake network, they're called validators there are a little bit different. And we'll get into that when we talk about proof of stake in this proof of work system. All these nodes are competing against each other to find the answer to the blockchain riddle. Remember, in our example, it was to find a |
hash that has four zeros at the start. And again, depending on the blockchain implementation, that riddle is going to be a little bit different. But all the nodes are trying as many as possible to try to get this answer first. Why? Because the first node to figure out the answer to the blockchain real is |
gonna get that transaction fee, they're gonna get paid from that. Now, when a node gets paid, they actually get paid in two different ways. One is going to be with a transaction fee. And another piece is going to be the block reward. Remember how we talked about alternating the gas price or the gray on our transaction? Well, that's the transaction fee that we're going |
to pay to these blockchain nodes for including our transaction, the block reward is given to these nodes from the protocol from the blockchain itself. You've probably heard of the Bitcoin halving before the halving is referring to this block reward getting cut in half and it's supposed to be cut in |
half, roughly every four years. This block reward increases the circulating amount of whatever cryptocurrency that is being rewarded. For example, on Aetherium the block reward is giving out Aetherium and a Bitcoin the block reward is giving out Bitcoin. So these nodes are competing against each |
other to be the first one to find this transaction to be the first one to find the answer to this problem, so that they can be the ones to win both this block reward and your transaction fee. Some block chains like Bitcoin, for example, have a set time when they're no longer going to give |
out block rewards and the miners or the nodes are only going to get paid from trends. Action fees. Now this gas fee, again is paid by whoever initialize the transaction. When we got our funds from the faucet, there was some server and somebody else was paying the transaction fee for us. However, when we sent |
ether from one account to another, our first account actually paid some transaction fee to send that ether. In proof of steak. There's also a gas fee, but it's paid out to validators instead of miners. And we'll talk about that in a little bit. Now let's talk about two types of attacks that can |
happen in these blockchain worlds. Let's talk about the first one being the Sybil attack. The Sybil attack is when a user creates a whole bunch of pseudo anonymous accounts to try to influence a network. Now, obviously, on Bitcoin and Aetherium, this is really, really difficult because user needs to do all this work in proof of work or have a ton of |
collateral and proof of stake, which again, we'll talk about in a bit. The other more prevalent attack is what's known as a 51% attack. Now, as we saw as part of our consensus protocol, these block chains are going to agree that the longest chain is the one that they're going to go with, so long as it matches up |
with 51% of the rest of the network. This means that if you have the longest chain, and you have more than 51% of the rest of the network, you can do what's called a fork in the network, and bring the network onto your now longest chain. Now Sybil attacks, obviously, are when a single node or a single |
entity tries to affect the decent reality of the network by pretending to be multiple different people, although they're just the same person or entity. And like I said, it's really difficult to do in proof of work and proof of steak. So you can see now that blockchains are very democratic, whichever blockchain has the most buy in and is the longest is the |
blockchain that the whole system is going to corroborate. When nodes produce a new block and add to the longest chain, the other nodes will follow this longest chain that the rest of the network is agreeing with, add those blocks to their chain and follow up. So very small reorganizations are actually pretty common when a blockchain picks a block from a different |
longest chain puts it on and then has to swap it out for another block and continue with a different blockchain. However, if a group of nodes had enough nodes or enough power, they could essentially be 51% of the network and influence the network in whatever direction that they want it. This is |
Subsets and Splits