Episode 80: Stratum V2
Ep. 80

Episode 80: Stratum V2

•

Episode description

In this episode of Bitcoin, Explained, Aaron (@AaronvanW) and Sjors (@provoost) are joined by Braiins co-founder Jan Čapek (@janbraiins), who has been leading the initiative to upgrade pooled mining to the Stratum V2 protocol. Aaron, Sjors and Jan discuss what pooled mining is, how the Stratum protocol helps with that, and in what ways Stratum V2 is an improvement over Stratum V1.

Episode Sponsor: https://voltage.cloud/

Sjors New Book: https://btcwip.com

Transcript

Download transcript (.vtt)
0:20

Aaron van Wirdum Live from Prague, this is Bitcoin.

0:23

Sjors Provoost Explained.

0:24

Aaron van Wirdum Hey, Sjors.

0:25

Sjors Provoost Hello.

0:25

Aaron van Wirdum Sjors, we have a distinguished guest today.

0:28

Sjors Provoost We do.

0:29

Aaron van Wirdum Jan, welcome to the show. Jan Čapek. Is that how I pronounce it?

0:33

Jan Čapek We actually say Čapek, but you did a pretty good job.

0:37

Sjors Provoost Čapek.

0:37

Aaron van Wirdum I think that's exactly what I said, Jan. So you work with Braiins? and we're gonna talk about Stratum V2 yeah we have two mics which is gonna be awkward sometimes you maybe hear someone talking in the background I'll just give the mic to you and then you can sort of introduce yourself how about that

0:53

Jan Čapek Hi guys. My name is Jan Čapek. I work for Braiins. I'm a co-founder of Braiins company. We started back in 2013 by basically making the first Bitcoin mining pool, a professional project. And since then our Bitcoin adventure started back in the day in 2018, we came up with the idea of extending our product line with mining firmware. So we implemented support for Antminers S9 and we call that project at that time Braiins OS. Then we had, it was like fully open sourced. By the time you could have all the data sheets for S9, the source code and everything, even from the manufacturers. So we kind of continue in that, in that line. Then we came up with a commercial extension called Braiins OS plus, which provides some additional features like optimized chip tuning of individual hash boards. And here we are 2023 and we're like slowly walking towards having our own mining hardware. We have now a control board coming in June and in Q3, we will have a PSU. So we're like approaching this product line from all the different aspects. And at some point there should be Braiins miner available.

2:00

Sjors Provoost Yeah, and you gave a talk during Pizza Day Prague, which will hopefully one day be on YouTube. That is super interesting about this control board and all sorts of problems with that.

2:09

Jan Čapek Right. I gave a little overview of the issues that I see in the mining industry. And generally, the note was about the fact that people kind of take Bitcoin mining for granted. Not too many people actually look into it, except for the miners themselves. that is a great source of revenue for them but general Bitcoin users think like oh we have Bitcoin miners here but when you look at the details there are some centralization issues coming mostly from the fact that there's just a few players in the game mostly from China that basically keep the whole market for themselves. And it's a very motivating and incentivizing fact for us to actually enter the business as Braiins.

2:49

Sjors Provoost Yeah. But I think today we'll be mostly focused on the software side of this story and not so much in the hardware side.

2:56

Aaron van Wirdum First though, Jan, do you ever listen to our podcast?

2:59

Jan Čapek I think I did once.

3:00

Aaron van Wirdum So you know what everyone's favorite part of the podcast is, yeah?

3:04

Jan Čapek Which one is that? Tell me.

3:07

Aaron van Wirdum Sjors, do we have the boostagrams on the road?

3:09

Sjors Provoost Yeah yeah we have them yeah

3:11

Aaron van Wirdum Do you know the jingle?

3:12

Jan Čapek I don't sorry.

3:14

Aaron van Wirdum I'll I'll do the jingle then Sjors stacks sats. Sjors stacks sats. Sjors stacks sats.

3:22

Sjors Provoost Well, well, well. So we got a couple this time on the last episode about the witness discount. One is from fake for 10,000 sats, he says Sjors stacks sats and stays humble. Apparently. Then we have one from shadowycodermark, 9,400 sats saying, Van Wirdum, Sjorsnado. So he likes the old name of the podcast. Then somebody said that he thought I was an opera singer.

3:47

Aaron van Wirdum No, that must be me, Sjors.

3:49

Sjors Provoost That's possible.

3:50

Aaron van Wirdum For sure.

3:51

Sjors Provoost Somebody even asked a question, which I answered. So I won't repeat the question here. But sometimes I will answer boosts. Well, that's about it.

3:59

Aaron van Wirdum Sjors stacks sats. Back to the episode. Okay, Stratum V2. Jan, first of all, okay, first, what is actually Stratum? What is Stratum V1? Let's start there.

4:13

Jan Čapek Stratum V1 didn't have the attribute of being V1 until we invented the V2 so it's been known publicly until V2 as Stratum mining protocol so essentially it's a protocol between the Bitcoin mining machines and the pools so that pools can distribute jobs to the miners in a scalable way so it has some mechanisms to adjust difficulty of these mining jobs for the machines in case of huge farms connecting to the pools so that these pools can handle such loads so this was the the biggest added value compared to getblocktemplate back in the day where this was the old way of mining basically directly against the Bitcoin node to allow like scalable approach and even more than that you could have aggregate you could have aggregated the full hash rate on the mining farm through proxy and there would be then just a few connections going to the pool acting as if it was one gigantic miner Unfortunately the protocol so so fortunately we had the protocol

5:12

Sjors Provoost I wanted to interrupt you a little bit to maybe zoom in a little bit or recap how mining works period because not all the listeners will know that so well the short story is in order to create a new block you need to find a nonce which is a random number or pseudo doesn't matter it doesn't have to be random but you have to find a number such that if you add it to the header of the of the Bitcoin of a block, if you then hash the header, you get a bunch of zeros at the start. That is the challenge you're trying to find. And then the difficulty adjustment based, to put it simply, the difficulty adjustment means that if blocks are found too quickly, then you have to add another zero or not really another zero, but basically it just becomes more difficult because in order to have more zeros at the start of a number, you have to do more random guesses. So you have to try more nonces. And then initially miners would just be the CPU of a computer, the one CPU, one vote idea. And as more CPUs started mining, they would have to add more zeros. But then somebody figured out how to do it on a GPU, a graphical computer, graphical processing card. And then I think a little bit later, well, and then later on, you got these dedicated chips basically. But, and that brings, I think it brings us to the problem of pooling, where you have multiple, where it's no longer a good idea to try and mine yourself because you'll find a block once every 2,000 years or something.

6:41

Jan Čapek Depends on your hash rate.

6:42

Sjors Provoost Right. And so then you want to join with other people and distribute the work. And the reward. And the reward. and then well this is where we get into what getblocktemplate is maybe and what what problems started to be caused when you're trying to share the work.

6:59

Aaron van Wirdum Well it was invented here in Prague pooled mining is that right? yeah don't hear me in the background Sjors, it's just a quick question.

7:06

Sjors Provoost It's fine.

7:06

Aaron van Wirdum Sorry, listeners.

7:07

Jan Čapek Yes it has been invented here in Prague the the concept of pooled mining we're basically the first Bitcoin mining pool in the world the concept has been discussed for a long time on BitcoinTalk so There have been more people interested in these things, but I would say the quality changer or the shift, the major shift was actually with introducing the Stratum protocol by Slush back in the day.

7:31

Sjors Provoost So initially pools did not use Stratum at all?

7:34

Jan Čapek They were using the getblocktemplate and there were, I think there was one more mechanism.

7:39

Sjors Provoost But getblocktemplate just... Well, it's an RPC call to Bitcoin Core and it gives you a block and then you can add, it basically puts all the transactions in there and you can add your own coinbase transaction that sends it to yourself. Right? That's what the thing does. But then how do you use that in a pool?

7:55

Jan Čapek Well, the pool was providing a little bit of abstraction about this, but it was not meant for thousands of machines connecting to it because there was no way to adjust the difficulty for it. You would be either getting spammed by all the shares from the machines or you would never see a share. And then the problem was that it was difficult to measure it. And then when you had to distribute the... the reward and there were issues associated with that. So conceptually, it was something that just did not scale at all.

8:27

Sjors Provoost So the concept of shares was invented first, right? Because the idea of a share is that you try to produce a block, but instead of the actual difficulty, you take an easier difficulty. So you say like, okay, the block has difficulty 1000, I'm just picking a number. If you can produce a block with difficulty 10, we count that as 1% of effort. And somehow we track. And that's how you prove that you're actually putting in the effort. So you're sending all these blocks at 1% of the actual difficulty.

8:53

Jan Čapek And it's even more advanced in a way that, for example, pools specifically choose how often they want to see a share, like just statistically. So, for example, our pool is configured so that it gives difficult enough jobs to its miners so that they produce a result, let's say, every five seconds.

9:10

Sjors Provoost So instead of saying, I want a certain percentage, you're saying, I want to see a share every five seconds and I'll make it easier for you if you can.

9:18

Jan Čapek This is correct. And this share that you submit has the value of the difficulty that I give you. So for example, if it's a weak miner given a difficulty one, because it's some USB stick, for example, those old Block Erupters, they were able to mine like difficulty one share in like 20 seconds, right? Which is far behind the expected performance. So you would see big variations in the hashrate. But these devices are no longer relevant. But to compare it, so these devices would be given, for example, difficulty one, and they would barely produce a share every 20 seconds. So they would get this one point in our accounting, whereas some ASIC has difficulty 8,000. So every share that they generate is 8,000 points for them. So once the block is found, then you see the ratio of contribution to finding the block.

10:08

Sjors Provoost So that was the problem that Stratum solved, is that you could not give every device its own target, essentially, its own difficulty target.

10:15

Jan Čapek Yes, this is exactly the added value that now it actually scales because the pool can protect itself from being basically DDoSed by the machines.

10:25

Sjors Provoost And the DDoS risk is, I guess, but I mean, the pool could have just set the difficulty more high, but then the problem would be that the smaller miners can't participate anymore, right? So it's a trade-off between... making it accessible for anybody with a reasonable machine, but also not getting so many shares that the server gets overloaded. from the from the very fast machines right.

10:46

Jan Čapek And there was another aspect as well because it was essentially like request response based like HTTP kind of protocol originally so it was not that the miners were keeping a permanent TCP connections but the servers were also harassed by by by the miners like connecting disconnecting all the time just to get the job and to some of the result so so the the protocol itself the getblocktemplate stuff was not really meant for like scale mining it was just suitable for like your home own home setup let's say when back in the day when you didn't mind using pools but you were basically solo mining everybody at the beginning of Bitcoin history was pretty much solo mining on their CPUs then maybe GPUs and then at some point it became infeasible to to mine on your own and the reason being the probability of finding the block is still the same but what is stepping in is the variance because what some people don't know, it's good to repeat it, is that you mine… Bitcoin in blocks and they have the fixed value. You cannot mine one Bitcoin. The subsidy in the block is given by the protocol plus the transaction fees. Technically, I don't even know if you can set it to like one and see what would happen because it's below. So I don't want to refer to the source code.

12:02

Sjors Provoost It would be possible, but it would be stupid.

12:05

Jan Čapek But generally, you mine it in blocks and that means that I cannot with a mining machine that's less performant, mine just a fraction and be happy with it. The only way to mine the fraction is to join the pool. with with all the computing resources and proportionally receive the reward based on the on the mined blocks of such a huge computing cluster and typically back in the day the the hashing power was rising really steeply every month and it became unfeasible for these solo miners so they were gathering in the pools and we were so we were one of the first we were the first Bitcoin mining pool

12:40

Sjors Provoost and so let me see what did the name Stratum come from?

12:46

Jan Čapek Honestly, I don't know. I know the history that Electrum Wallet actually has some protocol, and I think the name was coming from there. But I'm not the original author of the Stratum V1 protocol.

13:01

Aaron van Wirdum Okay, I think so far we discussed the concept of mining and how it works with shares and how Stratum sort of plays into that, but that doesn't cover all of Stratum, right? We haven't broken down everything that Stratum is or does, I think.

13:15

Sjors Provoost I think the two things you mentioned so far is that it's able to give different difficulties to different machines and that it communicates with something a little bit more efficient than HTTP requests.

13:25

Jan Čapek Right. So this was the quality shift, but still there were some deficiencies in this protocol. So we have to realize that we're dealing here with like money printing or money generating machines. So even back in 2013, it was quite valuable not to make too many programming errors and lose the Bitcoin. For example, by mining to an invalid coinbase address or generating invalid shares because of one bit being flipped or reverse byte ordering or anything. So back in the day, it was actually a wise approach by Slush to come up with a protocol that would be easy to use and easy to debug. But here we are back in 21st century, where 2023, where the protocol still exists, but has like these tiny flaws in a way that it's not efficient because it's text-based. It was easy to develop with such protocol. You could technically telnet to your mining server and just talk to it and pretending you're a miner and you can easily verify that it's generating the proper jobs. Second part is that there have never been like an official central go-to place with a specification. Bits and pieces are on the Bitcoin Wiki. Some version of the protocol is published on our website, for example. And there are other sources of truth, let's say. That would be the least important problem. The major problem is that throughout the time, there were different flavors and dialects actually implemented, sourcing from the fact that even the manufacturers of the mining machines, eventually with the rise of ASICs, they were not able to go to one single place and implement the protocol correctly. Back in the day, I remember like regularly on regular basis in 2013, 2014, really tweaking the mining servers so that they're able to talk to these Stratum compatible ASICs because this was the time when new ASICs were being introduced to the market. And every now and then you would have some exotic version of the firmware that would not comply. And that's actually also the time when I was thinking like we should be providing also the firmware to eliminate this degree of freedom and potential issues. Because bad things could have been happening. Like if the machine is not, for example, rolling the timestamp properly, or if it's not doing something else, or if it's producing invalid shares, then somebody was actually wasting energy, right? Because these jobs cannot be acknowledged as valid or these shares. So this was one deficiency, not having like a central standard for it. The fact being text-based means quite a bit of inefficiency. A lot of text strings that represent different messages like mining.submit or mining.subscribe. mining.submit is probably the most... frequently cited piece of text on the internet in my view because it's like terabytes and terabytes of these strings being sent like every second.

16:25

Sjors Provoost So mining.submit means like I'm here by sending a share.

16:28

Jan Čapek Yeah, it's me and mining.submit a bunch of stuff. That's not necessary. You can have one constant or use of standard protocol for this.

16:35

Aaron van Wirdum Why is this a problem specifically?

16:37

Jan Čapek Wasting bandwidth. So there are use cases where you want to be a bit bandwidth savvy. And it's not just about the bandwidth, but it takes additional time that eventually at the end of the day, what that can mean is that your share is going to be considered invalid just in case you'll be racing against a block that has been just found in the network. So every little piece of inefficiency counts towards you not mining as efficiently as you could.

17:06

Sjors Provoost Yeah, there's 600 seconds per block on average. yeah if you're wasting one second you're wasting one six hundredth of your revenue pretty much so seconds matter milliseconds matter

17:18

Aaron van Wirdum yeah and one thing you haven't mentioned oh by the way just to make this clear it's always good to sort of break it down to the basics Stratum the people running Stratum so it's the mining pool it has a server and then you mentioned the actual miners or sometimes called hashers they have it on their machines and these machines talk with the servers so they are using Stratum and what you mentioned is that because it's not even strictly standardized sometimes they don't really communicate well that's what you're saying right that's one of the problems that

17:45

Jan Čapek that's that was that was one of the problems back in the day nowadays I don't remember a single issue because I mean Once the protocols got stabilized, I would say like everybody's kind of scared of touching it. So the manufacturers don't make any changes in the CGMiner code base for this. And the pools already have implemented all these hacks for all the different flavors of the firmware. So not too many issues arise now, but really back in the day, it wasn't a month where we would have to deal with some farm, like not being able to submit shares or something like this to accommodate for this.

18:19

Sjors Provoost You mentioned CGMiner. from what I remember that's the mining software that was used on GPUs or even on CPUs and it was just shoved into ASICs and adjusted to live inside an ASIC right

18:31

Jan Čapek maybe a description of like that residing in an ASIC is not very precise but yes so this was the This was and is still the mining software being used by most of the manufacturers. This is the software that they actually violate the GPL on.

18:46

Sjors Provoost I was going to say, because wasn't that open source?

18:48

Jan Čapek It is open source. Back in the day with Antminers S9s, Bitmain was still publishing the sources for CGMiners.

18:50

Sjors Provoost Or GPL even.

18:56

Jan Čapek So technically you could have put together your own firmware with like all the different bits and pieces, but it required quite a bit of skills. So it was not like... Git clone and just run some build. Because there are a few components to the firmware. It's not just the software because you have to think of the ASIC as a full computer. So it has a control board with a CPU that's driving these ASICs. There's an additional component between the ASICs, but I'm getting into too many details here. So it's a complex system. You can think of it as a full operating system image with a dedicated software for mining that is called CGMiner. Back in the day in 2019, we started developing our own for various reasons. One primary reason was that we wanted to be independent of the original CGMiner code base. We wanted to do in a modern programming language, which C is no longer considered to be the modern programming language. And last but not least... We wanted to have some kind of like business advantage or edge towards compared to our competition. So having something that has been fully built in-house from scratch, not violating any licenses, that's sort of where we were headed with that.

20:05

Aaron van Wirdum Okay. And also, so to take a small step back again, we just mentioned that the mining pool is running Stratum and then the machines are running Stratum and they're talking with each other. Before we get lost in the details, so who does what exactly? I think Sjors kind of explained this. Basically, the server does everything. The server constructs the entire block, includes all the transactions, creates everything, except for the nonce. So the whole thing is then sent to the machine, and the machine is just trying different nonces until it finds a [unclear] block. Is that right?

20:35

Jan Čapek This is exactly how it works. A little bit more complicated fact is that there's not just the nonce, but there are additional fields in the block header that nowadays... Thanks to Stratum V1 extension to support ASICBoost. We don't want to get into the ASICBoost topic here. But it's an additional feature to make the machines run more efficiently. So they're iterating more fields in the block header than just the nonce.

20:58

Sjors Provoost Yeah, to just quickly explain what the problem is here. If you have a CPU and the nonce field is, I think it was eight bytes or something.

21:05

Jan Čapek It's four bytes.

21:06

Sjors Provoost It's four bytes. So four bytes is not a lot of combinations. And so if you're really fast, you can make more combinations. And then there's no point in trying the same combinations again because you've already tried those. So you have to change something else about the block. And one thing that changes every second is the timestamp but you're still going to be too fast and so you want to change some other fields in the header and even in the coinbase transaction in order to keep up in order to try enough variation essentially.

21:31

Aaron van Wirdum Okay I'm gonna pull us back from the weeds again So one of the problems that we haven't mentioned yet, you mentioned a couple of problems in efficiency and non-standard protocol. One of the big problems, one of the ones that people are talking about a lot, is potential censorship. So because the mining pool is doing all the transaction selection, that means that the mining pool can potentially make sure that some transactions don't make it into the block, right?

22:01

Jan Čapek That is correct. So if you want to talk about the new protocol, we tried addressing it by protocol or sub-protocol extension that we call job negotiation. And essentially what that means is that the miner is able to generate his own block template and he only negotiates in an asynchronous way. So essentially he generates a template and starts mining on it right away. And in the meantime, he can negotiate with the pool if the pool considers this template valid. Because let's say... a rogue miner who would try to attack the pool would generate a block template that would mine the coinbase into his own pocket. But obviously from the pool perspective, this is not a fair game. So even though he would be submitting the shares, eventually it would be reflected in the pool accounting as invalid by the time such template is created. But there is another reason, not just because of pool censorship. If we find out that some pools are doing censorship, you always have the option because there's more than just one or two pools in the world. You can switch over to another pool that would not be doing these. immoral things let's say but the protocol is trying to get ready for future in case we would have some kinds of regulations stepping in basically forcing the legal entities behind the pools who are running the pool services to not select the transactions like let's say it would become illegal it would be it would require like additional certification or whatever regulations knowing the customers whatever And in that case, the pool would say we're just providing a data service and leaving the responsibility, even like the legal responsibility, up to the miners. It would be their choice. If they want to mine with this particular pool, they have to choose their own transactions. And we would just do the validation that the block itself is valid, but not giving them the full templates. So this is sort of like getting ready for the future.

23:59

Sjors Provoost So I hear there are some tokens involved here. But I'll explain it, I guess. So the idea is that when you propose a template to the pool and they approve it, then you get a token that basically proves that they approved your template. And my understanding is the point there is that eventually you're going to get paid for the shares you submitted. And so the only way the pool can enforce that you don't create a block that they don't like is by not paying your shares and vice versa. If your thing was approved, then you should be getting paid for that. So then if they're somehow not paying you out, even though they approved your share, you have a little signed message saying, hey, the pool approved this template and they didn't pay me. So you can make some noise about it.

24:41

Aaron van Wirdum So you can prove it to other miners and they will leave the pool. That's the idea?

24:45

Jan Čapek That's also the case. I mean, like the actual business scenario or the full process is not prescribed by the protocol. The actual policy is to be set between the miner or terms and conditions or business terms and conditions are to be specified between the miner and the pool.

25:04

Aaron van Wirdum Right.

25:05

Sjors Provoost So this is one way you could use it, but the protocol doesn't care how you use it.

25:08

Jan Čapek No, not really. There's more complicated stuff associated with that. And that relates to the fact like how you want to do the accounting. Because let's say you would be a miner who would be in favor of empty blocks as an extreme example. But that's probably the one that's really on the left side. But this can happen. Such a miner, if it's a major player on the pool, is essentially lowering the rewards for everybody else because the rewards are split in a proportional way. So there is no reason for somebody in the game to systematically lower the rewards for anybody else unless he has some special incentives. So that means the pool has to reflect this in their accounting and also depreciate the value of the shares that you're submitting because you're... for whatever reason you have a motivation you have you're submitting something that eventually ends to or leads to a block that would be less valuable than your your neighboring miners with uh...

26:07

Sjors Provoost so if somebody submits a template that has very few transactions in this…

26:10

Jan Čapek [unclear] zero as as a good example.

26:12

Sjors Provoost Yeah so you don't necessarily have to reject it you just say well okay, that's fine but your shares are gonna be worth less.

26:17

Jan Čapek Now, not worth less but less. that's gonna be worth less yeah

26:23

Aaron van Wirdum Okay, so we've been jumping a little bit between V1 and V2, which is fine, but I do want to clarify. So yeah, the difference was that miners used to construct the whole block with all transactions. No, sorry, the pools did. And then the miners, the hashers, the machines just made an answer. And then with V2, now the machines can do that. But it's optional, right?

26:43

Jan Čapek It's an optional feature of the protocol to be implemented by the pools. And on the miner side, it requires running additional piece of infrastructure as well.

26:52

Aaron van Wirdum Right. Was this the main motivation for creating V2?

26:57

Jan Čapek The main motivation for creating V2, from my perspective or from our perspective as Braiins, was that we want to solve our own problem. And the problem was that we developed the mining firmware back in the day. And when we wanted to have the commercial extension, our business model was that we were collecting part of the hash rate in form of a fee, right? Like 2.5% was the fee. But there was no secure way how to ship this hashrate to our endpoints. So we looked at the current protocol and we're like, this is not usable. Even if you build TLS on top of it or whatever, it just doesn't make sense. It doesn't have standard and anything. So we just sat down and came up with a draft of a protocol that would address these three aspects, not speaking of the job negotiation, because that was not the use case that we really shoot it for primarily.

27:46

Aaron van Wirdum So job negotiations is what we just discussed?

27:49

Jan Čapek Yes, this is what we just discussed. But we wanted to address the security of the protocol. So no more plain text. Everything has to be encrypted and signed.

27:58

Sjors Provoost So there's two aspects to being plain text, right? Writing everything out loud like a JSON file rather than binary. One is that it is just inefficient. And the other is that it is incredibly insecure because anybody who is in the middle of that connection can just completely change it.

28:13

Jan Čapek steal a little bit of the hash rate without you noticing.

28:16

Sjors Provoost And one of the things you explained in your Prague Pizza Day talk was that there is, or maybe, really are, I think, viruses that run on routers. And they will...

28:27

Jan Čapek They detect the [unclear].

28:28

Sjors Provoost They detect that it's because they hear the word, you know, Bitcoin share, the most frequent...

28:31

Jan Čapek What was it? mining.submit.

28:33

Sjors Provoost mining.submit, the most common word on the internet. As soon as the router hears that word, it's like, oh, you know what? I'm going to take 1% of... of when I see the submissions I'm going to change the pool or I'm going to change the username for the pool to me to the attacker basically and not all of it because that will be obvious but just just one percent and then you would just infect a bunch of routers near mining farms and you will be sucking up one percent of the hash power and people might not even notice it because there is a lot of variation between efficiency

29:00

Aaron van Wirdum So but isn't the coinbase embedded in the block?

29:03

Sjors Provoost Not the coinbase. so when you submit a share you have to send it to some place on the internet namely the pool, the IP address of the pool, and you have to tell the pool which user it goes to. So if you put your own username there, it gets accredited to you. But if you put Dimitri the attacker as a username, then it goes to the attacker.

29:20

Aaron van Wirdum Got it.

29:21

Jan Čapek and it I mean even even more sophisticated than that the the the virus can create connection to a different pool and just sort of like load balance between the connections like giving you 90 99 percent of the jobs coming from your primary pool and then the rest of the jobs from from his pool he doesn't even have to

29:40

Sjors Provoost he doesn't have to use the same pool right okay

29:44

Aaron van Wirdum so that's Let me get the mic. Okay, so we mentioned what we call job selection, apparently, with transaction selection. And now you mentioned security. And is there another benefit to V2?

29:55

Jan Čapek Last bit that we wanted to address was the efficiency of the protocol. So going away from the text-based protocol to a binary format reduced the bandwidth. And there was another two points to improve the efficiency. One of them being... The original protocol, when you get a new job, you don't get like the full block template, but you get, let's say the block header and what we call a Merkle branch. So essentially, let's say a chain of hashes of transactions, if you think of a list of transactions, if you organize it in a tree, and then the miner has to generate the actual Merkle root and the full block template and then start iterating the nonce. But whenever the miner submits this result, pool has to redo exactly the same thing because it doesn't know what additional data the miner actually injected into the block.

30:47

Sjors Provoost I guess we need to explain a little bit what a block looks like. So you have the header and then you have, I think it's something called the Merkle root. That's a field. And that says like, this is the Merkle tree of all the transactions that are in the block.

30:59

Jan Čapek Right.

30:59

Sjors Provoost And then part of that Merkle tree is the coinbase transaction.

31:02

Jan Čapek Yep.

31:03

Sjors Provoost And that's the thing that miners tend to vary a bit to. you know, to get some extra search space. But once you added the coinbase transaction, you then have to calculate the new Merkle root. And that means if it's like, if the tree is 10 levels high, then you have to do like 10 hashes. in order to update the Merkle tree again.

31:22

Jan Čapek Yeah, pretty much that is the case. And this is additional computing power on the server and of the pool to verify that the job is valid because he has to redo this Merkle calculation completely. So we have added a variant for mining, which is... let's say the default it scales up to something like 280 terahash machines where you're given…

31:44

Sjors Provoost which is about two times the speed of the current the current best.

31:48

Jan Čapek I think the hydros are now at like 250 but

31:51

Sjors Provoost okay, so they're now apparently we're getting close.

31:53

Jan Čapek Yeah but like I said it's it's an optional but very preferable way for for the machines it's important to realize that by the time we have been preparing this spec the hash rate was nowhere near this it was still like S9s you know something like 20 terahash 30 terahash coming so this was the inefficiency that that we wanted to address and last one kind of quite often cited in the public is the the issue with the with the empty blocks I personally don't don't consider empty blocks as a problem but there is still a way to make it a little bit more efficient and that is the new protocol is actually able to send the miner a speculative block template that...

32:33

Aaron van Wirdum Wait, wait. Why are there empty blocks?

32:36

Jan Čapek Why are there empty blocks? Okay, that's a good question. When a miner is submitting a job and a new block is found in the meantime in the network, this share is considered invalid and the pool has to immediately serve him a new job. But the problem is that it takes seconds to generate a full block template by the pool. That's just given by the fact that the new block basically determines this is what the transaction history looks like now. You have to adjust your mempool, you have to dig out all the important transactions from the pool. That's what the Bitcoin Core is doing. And then eventually you end up with a Bitcoin block template. And this takes literally like seconds. And you cannot stop the mining machines for seconds and tell them like, oh, wait, I'm going to give you block, but just wait a second. Because there are machines that are running and rolling the nonces and they have to, sort of like a racing engine, you have to keep it busy all the time. You cannot stop it.

33:32

Sjors Provoost Also, you just don't want to waste those seconds, right? Because it's revenue.

33:36

Jan Čapek Right. First, it's the revenue. Second, if you wasted them putting aside revenue, it actually costs you money because you're burning the electricity for nothing. So it's important for the machines to have a valid job as much as biggest part of the time as possible. And this is exactly the point where when the pool notices that there's a new block in the network found, it immediately serves empty block templates to all its miners. as an immediate update to flush all their jobs from from their pipelines and start hashing on this because it is [unclear] from from miner revenue perspective you or from from like the global Bitcoin network perspective because we're not wasting this electricity we're creating some value even though somebody can speak up to this saying oh but what is the value when when the block is empty you didn't create any transactions or you didn't put any transactions into it but that's not that's not That's not the problem because you simply don't want to have this electricity going down the drain just because you're not able to provide them a meaningful work. So this is what's happening now. And in the meantime...

34:42

Aaron van Wirdum Yeah, to clarify, so the only way to make sure that you're not creating an invalid block is creating an empty block. That's the only way you're sure you're not creating a block that includes a double spend, right? That's the idea, essentially.

34:54

Jan Čapek Yeah, that is correct. But with the new protocol, what we try to address is that if you look at the mempool and the set of transactions, you can say there could be a set of transactions somewhere in the second half of the mempool that are not going to make it into the present block. But you can still speculatively prepare a template because you have plenty of time for this. And this is something that you can distribute to the miners. And the moment a new block is found in the network, you are in parallel producing a new template, that's for sure. That's the number one activity that the pool is doing. But in the meantime, instead of serving the empty block, the pool can very quickly verify that the template that it has distributed to the miners some time ago is still valid. And the pool will just tell the miners, please use the template that I sent you five seconds ago with some ID, whatever. And then that's the moment where it becomes more efficient and we are lowering the probability of empty block being found. What hasn't been said yet is that the fact that the miners are given empty block template doesn't mean that we're going to have immediately an empty block. There's some certain probability to find the block given by the Poisson distribution. That's like the statistics behind Bitcoin mining, because finding the blocks sort of follows the Poisson distribution. So in the meantime, most probably the pool will still generate the new template and will distribute it to the miners the moment it has it. But this is as another mechanism to make, let's say, this situation better.

36:27

Sjors Provoost So I guess then if you look at it as a time lapse, so before a new block is found, the pool is already constructing some potential speculative future blocks, saying, well, probably this will be the next block. And it will give it to the miner saying, hey, hold on to this thing somewhere in your memory. And then presumably it will also give an empty block to the miner saying, hold this somewhere else in your memory. And then when the new block is found, I guess the first thing it will tell the miners is, hey, start mining the empty block because I still need to do some checks. Because some evil other pool could say, hey, I know these guys are using the second half of the mempool, so I'm going to deliberately put unexpected transactions in my block so that their speculative block is invalid. And then once the pool has checked that there was no shenanigans so that the template is valid, it says, okay, now please use this other template I sent you. And this way the miners can always be busy because they don't like doing nothing and it'd be wasteful to do nothing. So I guess, yeah, I guess first they will just be mining the original block. Because there is some time that you don't even know there's a new block. Then they mine an empty block. And then very quickly afterwards, they mine the speculative template. And then when Bitcoin Core is doing its three-second slow job, it says, here's an actual block that you should be working on. That's the adventure in the space of a few seconds.

37:42

Aaron van Wirdum Can I simplify this and then you correct me if I'm saying it wrong? So let's say there's 5,000 transactions in a mempool. I'm obviously picking a dumb number. there's, let's say, 1,000 transactions per block. Then what this protocol would do, you're first mining the first 1,000, but then the speculative one would be transactions 2,000 to 3,000, or maybe 3,000 to 4,000 to be sure. And that would be, so usually another rational miner would pick the first 1,000. So therefore, if you're going for 2,000 to 3,000 afterwards, then that should be fine. That's the idea in a very simplified version.

38:21

Jan Čapek Yeah, I think you summarized it really well.

38:23

Aaron van Wirdum Okay. What are the problems? Are we done now? Has mining now been solved, Jan? First, before I ask this, did we cover Stratum V2 sufficiently? Is there anything else you think we should add?

38:40

Sjors Provoost I think we've got everything, but you have the summary.

38:42

Aaron van Wirdum I mean, I have a summary. So yeah, what we mentioned is the transaction selection is moved to miners, or at least optionally. It's more secure, it's encrypted, it's authenticated. And then what we just discussed is the efficiency, which has different aspects to it. And that would cover it, right?

39:01

Jan Čapek I would say so.

39:02

Aaron van Wirdum Okay, so is mining solved?

39:05

Jan Čapek I would say for the time being with the protocol, it's solved. We're still kind of waiting when it would be the moment when manufacturers will adapt it. But at the same time for us, it's a business advantage that we support the Stratum V2 protocol natively in the firmware. And no other firmwares as of now support it. It looks like some aftermarket firmwares are going to adapt it eventually. And then the same thing is going to happen on the pool end. Especially thanks to the open source initiative that's now really agile and active behind the Stratum V2 protocol that we originally provided. The draft of the specification there are actively discussing with the guys like what should be the final form. And in the meantime, we've been like actively using the protocol for, for, for years without too many changes, let's say.

39:54

Sjors Provoost And there's some other good news because this, you know, switching to a new protocol brings us a bit of a chicken egg problem. Like you want all the firmware, you want all the nodes of all the pools to start supporting it. You want all the miners to start using it in their firmware, but maybe they don't want to do that unless everybody else is doing it. So there's something called the proxy or translator. I mean, which will take a V1 old school Stratum miner and we'll just translate we'll just pretend to be a V1 pool and then it will translate to the V2 pool so you do not have to update firmware for the miner.

40:26

Jan Čapek That's correct. And if you assume basic network level security in your facility, so let's say nobody tapped into your local network and when you're running all the hashrate through your proxy that eventually is able to aggregate this hashrate into a couple of Stratum V2 connections, you're pretty much safe because there's no easy way on the way up to the pool that somebody could tamper with the hashrate. Which even like... I can think of like conspiratory scenarios where with Stratum V1, somebody could be attacking even the BGP routers. So it's not even in your network or like your end router, but it could happen on the way. I'm not saying it's happening, but like technically anybody like these three letter agencies, that's an interesting data because from the hashrate, you can actually extrapolate quite a few things. Like you can estimate what what the size of the facility that's mining actually is, and all these kind of interesting things that could be found on the way just because of the fact that the traffic is plaintext, unencrypted.

41:36

Sjors Provoost So that's a privacy aspect there. So by encrypting the traffic, you also hide how many shares there are.

41:41

Jan Čapek Exactly, you're hiding your hash rate. It's only the pool knowing who's connecting.

41:46

Sjors Provoost And I guess one reason why you're really hiding it is because the hash rate is adjusted based on getting a certain number of shares per second. So because otherwise, if you're sending a share every so many difficulty units, then you can still see how much traffic there is and you can still figure out how big the pool is. But that's not actually interesting now because the difficulty is adjusted for each miner. So a giant pool will send one share every second and one little CPU will also send one share every second. So then the NSA cannot tell based on…

42:18

Jan Čapek Exactly, you can you can because the pace is given by the pool not by the miner and you cannot draw any conclusion from just seeing I mean you can statistically say like which encrypted messages are most probably the shares but you don't know what's inside. So you're missing the fundamental piece of information, which is the difficulty. So that's the value of the share. And then you cannot extrapolate how big the operation is.

42:42

Sjors Provoost So now the spy agencies have to hire a little bit more staff so that they can look at the electricity use near those IP addresses where the pools are from, and they can still figure it out.

42:51

Jan Čapek Sure. Well, that's an extra effort.

42:53

Sjors Provoost Exactly.

42:55

Aaron van Wirdum Okay. I do want to mention two things that Pavlenex mentioned in his presentation yesterday. So two problems that are not…

43:02

Sjors Provoost At BTC Prague, the conference.

43:04

Aaron van Wirdum That's right. Where we are. So one of them is pools can still opt to not pay out at all. So for example, if you're a miner and you're going to include transactions that the SEC doesn't like, then the pool can just say, well, we're not going to pay you out at all then. So that's still one risk, I guess.

43:26

Sjors Provoost Well, they'll reject your share. And once the share is rejected, the idea would be that you try another pool. And if you can't find any other pool that will have your share, I think the idea is to fall back to solo mining. So if pools start doing that, you'd see lots and lots of people solo mining briefly. Of course, that's not economical, but still.

43:47

Jan Čapek Well, these people will eventually form another pool, right? I mean, this is all about these consortiums or groups of miners that voluntarily get into this relation because they want to fight the variance when finding blocks. So I personally still don't see it as an issue because like anytime a pool tries to attack the miners in this way, you have the option to switch over to another one or exactly as you explained, eventually you can resort to solo mining or actually gathering with some like volunteer miners. who have enough moral integrity that they're not going to steal from each other, and you will sort of socialize the pool for yourself.

44:26

Sjors Provoost Yeah, so it's important because some people forget that pools are not in charge. Even in the current system where the pool decides what's in the block, you can just choose another pool if the pool is doing something weird. That's just made it slightly easier, I guess. And anybody can start a new pool if the current pool starts misbehaving, and then anybody in the world can just use that pool.

44:46

Jan Čapek Exactly, that's the case.

44:49

Aaron van Wirdum The other thing I want to mention and I don't actually know what this means exactly I just wrote down the words So one of the problems is share accounting. Does this ring a bell for you? Do you know what he would have been talking about?

45:01

Jan Čapek I think it refers to the job negotiation protocol when you're selecting your own transactions and creating your own mining jobs. Then it is an untrivial task for the pool to have a reasonable share accounting for the reasons that I describe. Let's say you would be a miner in favor of empty blocks. So you're basically penalizing your colleagues in the pool because you're pushing their rewards to lower values. You know, you have seen what's been happening with BRC-20, where the block rewards were, or the transaction fees in block were much higher. And these are all the BTC that also go to the miner or to the miners aside of the standard block subsidy. So these guys would have to be penalized and you have to have some smart system how to do the share accounting on your end. I think this is what was meant by the share accounting.

45:55

Sjors Provoost And there was also a presentation during the hackathon day or basically the developer day two days ago at BTC Prague by some of the Stratum V2 developers. And they were proposing a coin pool, which we did an episode on, on coin pools in general. And they proposed a way to use a coin pool to put the rewards in there. so that the pool is not even holding on to your coins, because that's still a little bit of a risk. And that was a pretty elegant design, except that you have to know before the block is mined how much you're going to put in the pool. But if people can select their own blocks, then you don't know how much is going to be mined, because it depends on which miner actually finds the block. So then you probably still need to agree on some sort of minimum fees that should be in a block. Otherwise, you run into some problems. So it's not entirely solved, but it's most certainly much better.

46:48

Aaron van Wirdum Last question. What's the call to action? Who needs to do what for this to become a success at this point?

46:55

Jan Čapek I think it's already becoming a success considering the size of the movement behind it. There are companies, not just us, but there are other companies that are officially listed on the website that subscribe the sponsors of the project and that have an interest in having this finalized and implemented on their pool. potentially in their firmware. So I think this is actually becoming a reality. Now, call to action, just check out the Stratum V2 protocol website. And if you have any of the skills required, ranging from, I think Pavlenex did a pretty good advertisement on this. If you have skills for website design, if you're a coder or whatever, just join the community and you can contribute to this. If you're a vendor of firmware, just talk to the guys. see what can be done on the firmware side.

47:46

Aaron van Wirdum Yeah it's an open source project anyone can contribute anyone can use. yes essentially right. okay.

47:52

Sjors Provoost All right, well, in that case dear listeners, thank you for listening to Bitcoin

47:55

Aaron van Wirdum Explained.