Indexing Ethereum data throught P2P protocols

ETHCC 7 · 11 Jul 2024 · 49:11

Lola Rigaut-Luczak, with Lin Huang assisting, runs a workshop on indexing Ethereum data directly through devp2p, the peer-to-peer protocols execution clients use to exchange blocks. A short theory part explains how nodes find peers and request blocks, then participants write a small Rust program that fetches block data without a JSON-RPC node. She gives reasons to index, including tracking addresses, finding contract creations, studying biased-nonce signature weaknesses, and archiving history before EIP-4444 prunes it, which she says is due in six months. She notes the data is not verified in the workshop, though blocks can be checked. The indexer is an open-source pet project, not a product.

Speakers

Topics

From ETHCC 7, hosted by Ethereum France.

Transcript

Hi everyone, good morning. Okay. So if you stand here, the work can you do before? Okay. Staying. All right.

Good morning, everyone. So today this is going to be a workshop about uh indexing Ethereum data through peer-to-peer protocols. So you will have to do some work, right? You will have to write some code. Yeah. So if you want to do this part, you can actually uh go ahead and scan this QR code. This is some code that we are going to use for the second part. Um yeah, let me know if you all got this. Waiting a little bit more.

So first quick introduction. We are going to present ourselves. Uh I'm here today with Lynn. She is just in front. Uh she's a former IP consultant and now she has reconverted as a smart contract developer and she's going to assist me and especially for the workshop. So if you have any difficulties at one point, you cannot compile or stuff like this. You can uh go ahead and ask her. She will help you as best as she can. You can also talk between you if you you know you can help each other also. This is also an option.

And so what about me? Who I am? Um my name is Lola, I'm French. Uh so sorry for the accent. I'm a software engineer. I've been working in crypt in cryptocurrency industry for the past 10 years. Uh, but my focus at first was more around Bitcoin, Namecoin, Dogecoin, uh, those classic coins. Uh, it's only recently that I've got really interesting and that I've been deep diving into ATIM. So please be kind with me. I might make mistakes. Um, and all right, uh, another important note.

We are not here to sell you anything. Uh so what we are going to present today is a pet project. And the idea of today's talk is just to share something that we have done with the community. And yeah, we are not here to sell anything or product or anything. All right, so what is the plan for this morning? Um the presentation is going to have two parts. First part is going to be about understanding Def peer-to-peer. So DevPertoP is a set of peer-to-peer protocol used in Ethereum.

So this is going to be theoretical. First 20 minutes, 15 minutes, you will have nothing to do. So just relax. And second part will be the difficult part. It's the actual workshop where you are going to write a bit of Rust uh program in Rust, where we are going to fetch block data using DevPeer to peer, so using the knowledge we've just acquired in the first part. All right, everyone, everyone is going with this. Okay.

So first part, understanding dev peer-to-peer. And we are actually going to try to answer the question: how does Etarium seek blocks? So you might all know this. Is that Ethereum connect to peers and they are going to seek blocks from all the peers, right? This is how you can catch up on the chain. And they do that through peer-to-peer, not through GZON RPC. So the question is: can we actually do the same thing so we can index those data and not have to rely on a node already deployed. But yeah, also important, I forgot.

During this first part, if you don't have it, you can download Rust and uh cargo if you are staying for the workshop. All right. And so also first, before going into the subject, uh, why do we want to index the data, right? What can we do with those data? What is this important? We can actually follow uh addresses, activities, see who is interacting with who, to whom they are sending money, uh, so it can tell you a lot of great stories, right? Uh Bubble Map is actually doing this, and they had a really interesting presentation. Not working for them, but they are doing good work.

Uh you can also find smart contract creation, right? You can see how many smart contracts have been created, and uh you can also look at, for example, a specific smart contract like ERC20. Everyone knows about those, so uh you can look at those tokens and how many have been created. So, side note, you can only like with only the raw data, you are only going to be able to see about simple create smart contract creation. So when you create a smart contract on Ethereum, you are going to send it to nobody, so destination being uh empty. This is how you create a smart contract.

But with the introduction of opcode create tool, you can have a smart contract to deploy, which deploy a smart contract, and this is to see this happening, you kind of need the EVM, but we are not seeing EVM today. This is a whole topic on its own. So unfortunately, like there is more, it's actually something that I'm working on. So if you're interested, I can show you something, but we are not going to do EVM today. All right, so another thing that you can do, you can actually look up for biased nonce vulnerabilities. And this is actually why I'm here today.

So as a front project, I wanted to look at biased nonce vulnerabilities in ECDSS signature. And so, what are those kind of signature like vulnerabilities? When you have one of those, you can actually calculate private keys. So you can calculate private keys with only looking at blockchain data at signature, right? So, where do you have the most signature in transaction in blockchain? So I wanted to be able to fetch as much as much signature as I can so I can actually calculate private key, right? It sounds like a fun thing to do.

And it was. So same. If you are interested, I can show you how to do this. But please don't steal anyone's money. It's just uh it's just for learning, right? Uh another reason why you might want to do uh to index blockchain data uh would be EIP uh 4444. Who has heard about this? Nobody? All right, so this EIP is going to be introduced uh in January, uh so in six months, and it's going to remove all the historical data from Ethereum. So Ethereum nodes will only hold data for one year when this will be introduced.

So the historical data is going to disappear. We are not going to have access to this except for the company who already have those, so we are probably going to have to pay for those data. So if you want to have those, this is the time to do it. Do it today, start to archive uh the Ethereum blockchain, and you can of course do this by using uh the indexer that I'm going to show you. And I'm pretty sure if you are here, you have also reasons like um to like you have more example of use cases of why you want to index data, and please come and talk to me after. I will be happy to hear more about what you are planning to do.

Alright, so let's go. Let's go into it. What is dev peer-to-peer? Um, dev peer to peer is a set of Etarium network protocol. So it's only used in the execution client, right? So you have two uh layers in Ethereum, the execution one is a consensus one. We are only going to talk about execution layer, right? Dev peer-to-peer is only used in execution clients. In consensus clients and or consensus layer, they use another LIP uh another peer-to-peer protocol, which is called lib peer-to-peer. Who has heard about this?

But we are not going to see this. We are focusing on dev peer-to-peer. What can we do with those protocols? Well, we can do a bunch of interesting things besides thinking blocks, which is a topic that is going to be interesting for us. We can also find other nodes, all the peers using peer-to-peer. So this is a really important part also of what Ethereum does, right? What the clients not do. It's like to find new peer to connect to and to maintain a network, a peer-to-peer network. But I think since the merge, we kind of abandoned this idea.

So we will see we had a protocol to do that. The idea was to not use third-party service anymore in wallets, because well, this is not centralized, decentralized if you do this, right? It's centralized. You relied on a third-party service and you rely on them working correctly, right? So there were this idea at the beginning to try to have something that is peer-to-peer. And also because it was uh done in Bitcoin and all those uh fork. So you had the concept called SPV, which was how to use a wallet but keep it peer-to-peer and not have third party. And Ethereum tried to do that, but unfortunately it didn't quite work.

And so important thing also, uh, some of those use encryption. So some of those protocols uh are going to be encrypted, and well, we are going to have to implement this. Okay, so what are those protocols and sub-protocols? So going a bit further in the rabbit hole. So we have some peer discovery uh protocols, uh, like disk v4, this v5, DNS disk. This those are the ones to find new peers.

Um most important one is actually this V4. This is used, this is based on um Cadmelia, so similar to BitTorrent. Everyone heard of BitTorrent, all right. Um so in BitTorrent, we usually use this to find content, and Ethereum they use this to find new peer. Um but so peer discovery is really important, but we don't have quite time to uh show how to like to implement this. So this is the just being mentioned here, right? Then uh next protocol uh which is used and has to be supported by all the nodes is RLPX, which is a transport protocol.

Uh and so we are going to see this how to implement this uh a little bit later. It use RLP encoding, uh, but I don't know what the name means. I just think they use LP and IDDX at the end. So this one has to be um supported by all nodes. So if you are going to do peer-to-peer, you need this one. And then we have a bunch of sub-protocols. Those are not mandatory, they are also going to be called capabilities. Uh so we are going to call them capabilities in the next part.

Um most important one is uh Ethereum wire protocol. This is the one that Ethereum used to sync blocks. We are going to see more about it after. We also have the light italian sub protocol. Well, this is the one that was used for like client, but this is not maintained. I think this is going to be removed. We have like a P parity Light protocol. So anyone can actually propose their own sub protocol. And you might implement it on your node or not. You might use it or not. It depends on what you want to do.

But anyone can propose something. Another interesting one will be Snap, where you can download snapshot of states. So it makes like syncing faster. All right, so let's look at the one that we are going to be interested in for the workshop. That is going to be interesting for us. First message is hello. So this one is going to be systematically exchanged between nodes. Then other message, two messages that is going to be interesting to us is ping and pong.

So those messages are used to know if you are still alive. Are you still connected? Are you still answering? So quite often they are you are going to receive ping message where you are going to have to answer pong. Otherwise, what is going to happen? Well, they are going to disconnect from you and they are going to send you a disconnect message. So disconnect message is a polite way to say that I don't want to have a connection with you. So they are going to tell you before they disconnect and they are going to give you the reason. So if you don't answer to their ping message, if you don't answer the message, they are going to send you disconnect, you are not alive.

You also have a link for the official documentation. There is a lot more information than just on this slide. So go ahead and take a look. Okay, so second protocol that we are going to need for this workshop is the protocol, etiam wire protocol. This one has a lot more messages, and you might already notice some messages that are going to be interesting for us. So first one, get block headers, right?

We want to have blockchain data. Headers are part of the blockchain data. You also have uh get block bodies. So the header is not enough. In the bodies, you actually are going to have more information, like the transaction. And transaction is also something that we are interested in. So those messages kind of work as a request response. So that's why you have get block adders and then you have blockaders. Get blockaders being the request, the message we send to make a request. Blockhelders is the message we receive as a response with the data that we requested.

Another thing that is interesting, but we are not seeing this in this workshop. Uh so just mentioning it. It's uh get receipt and received. Uh you also have like new block. I'm sure it's on my screen, but you can show it here. New block. Uh so for for sometimes, for example, you will receive like messages uh without having requested anything. They are just notifying you that something has happened, and they are like gossiping on the network and sending more messages trying to gossip the information, right? So and all right.

Is a status message. Same as hello systematically, when you start a connection and you start to use this protocol, you are going to exchange status message. Why? It gave you like important information, like for example, network ID, because there is different kind of network on Ethereum. And you've discovered peers, but you actually don't know if they are on the same network as you. It's only now that you kind of know, right? They might be on testnet and you are on mainnet, and they are useless to you. So you cannot use their data, so you are going to send a disconnect message.

Okay. All right. So we have seen the protocol that we are going to use. Now let's see the full process. So this is an example of how uh Alice Node can sync blocks with uh BobNode once you connect to it. I did mention that we have uh encryption. So the first part is actually end check. So you are going to send an off message and you are going to receive a hack message and is give you the required information for encryption and decryption of the following message. So a little bit of a personal opinion on this.

I don't think this is like why in general encryption is quite a good thing. In this case, we are not dealing with private information. This is not really needed. Also, we already have a lot of information about you because we already have your IP, so and we know that you are running Ethereum. And kind of uh adds some complexity to the whole process. I don't know what you think about this, but this is my personal opinion on this. Uh maybe this is not needed. But all right, so we have completed our hand check.

So next step, we need to exchange the uh hello message. So Alice is going to send hello to Bob, giving our information giving to Bob the information about the capabilities. So, meaning which subprotocols, capabilities, they can talk, right? So if Alice is going to talk uh using the eth wire, uh Ethereum wire protocol, she's going to put it here, and Bob in the answer has to have it here. And it means that everything is alright, other right, well, disconnect. Uh but let's say everything is alright, we are talking the same sub protocols.

So we can we can enter the third phase, which is uh so I mentioned we uh so it's a uh et wire protocol, and we first need the first thing that we need to do is to exchange uh status. So, status is going to give us information about the network ID. So it will be kind of a shame if the peer that you pick is not you have done all of this, is not on the same network, but unfortunately, you're only going to know this once you are there. So you have to check you are on the right network ID with them.

Also, you can check that they are on the that they have the same genesis because it might be that there is a mistake and they show the same network ID but not the same genesis, and well, what do we do? Well, we disconnect. So you also have the block hash, which is the highest number, the highest block they are synced up to, right? So they give you this information, and this information we are going to use it. So it's quite important. Alright, so everything is in place.

Now we can start to sync. So we do our request, send get block headers. We ask them like which block we can we want to ask them, we send Ben is a request the block we want to start from. What is the limit? How many blocks do we want? Do we want 10, 15? But the highest limits, the mask is actually 1000, 1024. And do we want to skip some block and do we want to go reverse? So reverse is kind of nice because we can actually take this block hash and go from the top back to the beginning. So that's why we are going to use block hash, and this is interesting to us.

Okay, so we do our request, and the answer is going to be the header. But in the header, we only have the header information, we don't have the transaction. So we do the uh send get block bodies request. And for that we actually need all the block hash. That's why you have to do this in two parts. You need the headers to calculate the block hash. So you can send a get block bodies request with all the block hash. And then you have the answer. And I agree.

Um, because there is a lot of setup, but in the end, what is interesting is that you actually can have uh a batch of blocks. Like if we are going to compare it to JSON RPC, here we can have like uh 1000 blocks right JSON RPC is kind of like one block at a time but for JSON APC you don't have all to the to do all of this right at first so there is advantages and disadvantages so doing this like this right uh what also of the advantage of like doing it through peer to peer is that you don't need to deploy a node you are just going to yeah connect to someone and ask them for the data do we have question for the first part have you tried with some other EVMs like forks of polygon uh I didn't try it on polygon but I tried on uh for Binance uh and I think I can try yeah you can try on everything that is a fork of uh Ethereum so not all EVM because some blockchain EVM are like uh are supporting EVM but they have a different peer to peer like I'm thinking Falcon and but they use lay peer to peer uh but everything that is using dev peer to peer you can use this uh another question oh sorry I need to give you the mic yeah just curious um how fast is it compared with the RPC let's say if you had compare uh yeah so yeah I did it once so if you want one block JSON RPC right this is way faster.

If you want to uh like index the whole uh history. Yeah, so I didn't try with JSON RPC. I only tried uh uh as a benchmark for only one thousand blocks, and this method was faster than JSON RPC. Like factor of two or more? Not much, but because in Ethereum, how many blocks do you have again? Like you have like something like more than two million? Yeah, twenty, yeah. So you it um it will get f it will be faster using P2PR. And again, my code is not quite it was a pet project, it's not quite optimized, I think, compared to what other people have did with General PC where they they might have optimized something like this. But can can you sort of uh parallelize the like with RPC I could just send it in in in sort of patches uh like like a sync uh calls.

Yes. Okay, can you do the same here? Uh yes. Unfortunately I haven't done it yet, but I think yes, you can do it. Uh so you can do it actually connect by being connected to different peers, right? Uh yeah. I had a question at the step where we exchange uh the capabilities, the sub protocols. Uh if we decide to implement a node that supports all known protocols, and we want to accept any other node that implements any any one of them, does it work or or do we s have to send like five messages, one with eth wire, one with uh snap? Um it depends after you can support all the protocol.

There is some node implementation, they make a point in supported all the sub protocols. Uh after that it depends on your use case. But it's only if you are only going to communicate through if uh you are only need to be interested in if messages. But if you want to answer to all the messages from all the capabilities, yeah, you will have to answer all of them. It's it depends what you want to do by answering all of them. They all have their use case, right? They are here for a reason. All right, no more question.

Well, this is time for you to code now. So we are going to implement this at least. Yeah, a small part of it. And so what is what is our program is going to do? It's going to actually fetch a block using uh DevPetopia, what we've seen in Rust. So you can go ahead and uh again I have the QR code for the GitHub repo. And so for the next part, each slide is going to have a step.

It's going to be step zero, one, two. And this is going to match a branch on this project, so you don't actually need to code in Rust. You can just do git checkouts. I think it would be a bit easier. But then you can try and run the program and see it working. If you want to actually code it in Rust, please go ahead. Alright, we should be good. Okay, so first step, step zero.

Uh picking a node. So I did mention we are not going to do peer discovery, so we already need to have a node and have this this node information to connect to to put in the program. Maybe I can show you first what does the program look look like, right? Um so this is what you should have. Uh there is a bunch of Rust files, but the one that we are going to be interesting and focus on is the main Rust file. The other uh files are uh functions that help with uh what we just uh seen before, right? It's going to make things a little bit easier.

So if you are interested in looking in those functions and what they do, you can go and take a look. Uh otherwise uh we are just going to get focused to follow the process. Uh it's always going to be written in the main Rust main dot RS file. Um so yeah, I did mention the first thing that we want to do is to pick a node. Here, this is a node is IPv6. Uh I'm not sure it's working on this network. Please let me know if there is a problem, otherwise Lynn is going to uh show you for other peer. And yeah, so okay, now going back to the to the presentation.

So we need a an IP or peer. We need to know the TCP port we are going to connect to. We need to know this is uh remote ID, which is basically a public key. And uh we all need to know what network it is on because we like for this project for this um workshop, we are going to work on with Rinkaby network. So it's an old test net. And there is some information, right? The network ID that we are going to need. So the one that is already coded, it should work.

Should it doesn't call if it doesn't work, you can actually go on this website called CyberCoop. This is a crawler. This is an Ethereum crawler for peers. So it's another open source project that we have done. So same, you can run it yourself. And you can go and check how many peers there is for each network. And I think Rinkaby is network ID number four. You can see how many nodes there is.

It's a small network, but still there. Right. Everyone has a website. Okay. So next step. You can do git checkout step one. We have our peer now. We want to generate values for our hand check. So what are those values? We actually need a private key, which is a cryptographic private key. It should be the same that is used in remote idea, but because we didn't participate in the uh peer discovery protocol in the peer discovery round, we can just uh generate it on on now on the go. Uh we then need a nonce uh randomly generated preferably.

We need uh nephemeral private key, cryptographic private key. And we need a pad uh also generated randomly. Uh but I think in the code I didn't generate it randomly because I don't for me it's not that important. Those uh those data are public. Uh and this is again, this is just uh uh a small uh pet project, right. Okay. Um let's go for step two.

So our first interaction with the node. We are now sending a off message. So it has to match the EIP eight. I don't quite remember, I'm sorry, I don't remember what IIP8 is, but it has been implemented since 2015. So this is the only one that we need to support, right? Because if people have not running since before 2015, well they should update. All right, so it's quite easy in the code. You have two function, create the off message using the value we just generated, and then we send it through the TCP stream. So on the diagram from the diagram from part one, we are here, right?

First step of the hand check. Okay, uh now we want to handle the answer for the off message, so handling the hack message. Um so we wait for an answer through the TCP stream, and once we receive a message, we are going to decode it and uh retrieve some of the data that we are going to use then for the encryption. All right, so far so good. Okay, so we have completed our hand check.

Uh we have all the information, so then the rest uh of our uh interaction are going to be encrypted. Uh but yeah, so uh another step, we need to set up the frame for the encryption and decryption for outgoing and incoming messages. Uh so this is not a node interaction, but this is a function uh where it does a bunch of things. Uh if you are interested in cryptography, you can go ahead and take a look uh into the function. Uh all right now we are waiting for the hello message.

Um so like I mentioned, we this is important, we have to exchange this, and we need to verify that they actually support uh the Ethereum 8 wire protocol. And we are working with version 67 and 68 uh for uh the code in the workshop. So there is different versions of those capabilities, and they have different um kind of format message. So every time you change something, they are going to change a version. And for us is only going to be working with 67 and 68. So if you have been on the CyberCoupe uh website and that you have look at the node, you have those information about the capabilities uh and uh their version.

Once you receive this, you can actually decode it and take a look at it. So okay, um to take a quick break and actually show you how to how it works. Does it work? Can it compile? Surprise. Uh wait. And cargo R.

All right. It doesn't support ID for Iv6. All right. So if it doesn't support IPv6. Wait, you can use warp, warp key if you have it. If you don't, uh there is another QR code that linked to a gist. And I want to thank uh Medi, my antenna who did that yesterday. And there is a other peer that you can check that are not IPv6. So I'm going to try and zoom.

Uh no, not this. Okay. So there is not much. Uh sorry, on the log. Uh but you you can see the different steps, right? Uh waiting for the hack. So before we add uh sending off message, uh waiting for the answer, we receive the hack, we set up the frame, the frame setup is done, we're waiting for the yellow message, and this is the result of the hello message, right? So this is what you see when you connect to a node.

Right, we have a question? Yeah, you could just show the command and the code run. Cargo run scargo cargo R. Um, please you can ask your question. It's not really a question, it's just uh well. I did card run as well, and it panics at line 40 at the TCP stream connect. That's why I assumed it was IPv6 issue, but even switching to IPv4, I have the same issue. Uh respond from the Cypress uh call thing 1625, 83146 that work from A2.

I mean the D6. Yeah, it depends. They can accept you and they can disconnect from you. So I guess you maybe add uh uh issue where it's not 128, but it's actually received uh code one. But um we we can uh I will take a look with you after if you want. I'm sorry it didn't work for you. Um but otherwise, this is what we should receive. This is what uh hello message looks like. So we have the information about the protocol, same things, version can change.

Uh we have the client version, which clients they are um they are running. So here you can see they're connected to a get node. Uh you have a bunch of information about what version they have, so it's kind of a serious thing if they have vulnerabilities, right? You already know a lot. Uh and you have most importantly, you have the capabilities, right? You have eight uh version 66, and we have eight version 67, so all good, this is good for us. And 68, same, we support this, so this is good for us. So we can we can go ahead and keep doing this.

You also have like the remote ID. Um we are here. So we can send first or receive the message first, it doesn't matter. What matters is that there is an exchange of the hello message. And so step six is going to be us sending an error message. So you have um function that allow you to create a message, this kind of message easily, and then you can send it on the TCP uh network using the uh uh encryption uh value, the value to encrypt the data. Sorry.

Alright, so we are now here, and this phase is now complete, so we are going to enter the at wire protocol phase. So remember, first thing that we need to do is to exchange status, and with the status, we need to have the particular information about the network. Those information, like the most important information being the network ID. So at the beginning of the code, we actually choose which network we wanted to use. We wrote like Ethereum ring, and so it will uh give you the right network ID, for KD, Genesis hash for everything. So you create the status message with all those information, and then we send it through the TCP stream.

Alright, we are here. Send status. And now we are waiting for the answer. So for the other node to send the uh status message. So we wait, we just wait for it, wait for the message, then we decode it. Um yeah, we want to get the current hash. This is what is important for us. We want to know on which uh highest hash they have for a block. Uh all right, this is complete.

Now we can start to uh no, actually, we are not yet starting to um ask for messages. I'm sorry, there is actually implementation is a bit difficult, there is a lot to handle. Uh we are going to create a thread. Why we want to do this? Because I did mention that you can have receive ping message. And when you receive one of those, you want to answer pong message really fast, otherwise they are going to disconnect. So that's why it's easier to have a thread that continuously look and check for those messages. And if when you receive one, you are going to check that the code is the one for the ping, which is two, and you are going to send create and send an answer directly.

So you are not being disconnected, and you can keep doing this without it stopping in the middle of syncing. Uh okay, so getting block adders. Uh so using the current hash value that we got from the node, uh, we can craft the block header get blockaders message. Uh you can use also block num uh limits uh the max limits because we want to have a patch, right? All of them.

Uh the limits being uh 1024, and we are going reverse, and then we send it uh to the node. All right, we are here. Get block headers. And now we are waiting for the answer. So you when you are in this part, you might receive messages that are not message answer to requests you have done. So you are going to ignore those message. Uh the message that you actually want to check for block headers is the one that starts. So the first byte of the encrypted body that you are going to receive is actually the code of the message.

So you are going to want to check that to know which can what kind of message you're receiving. And we only want to to we are only interesting in message code 4, and the rest is going to be discarded. Alright, we are here. We are getting the response for the block headers. And now step 12. There is two more steps after we are done. Uh step 12, getting the block bodies. So we have the headers, now we want the transaction.

In block bodies, you also have uh the homeers, uh, so the anchor block, uh, which was something that was Ethereum was doing before the merge. Um we craft a message and uh we send it. Fortunately, there is a hard limit in size, so it might happen that you request for some block, but in the end they are not gonna be going to give you everything. So it's okay. You just ask again with the block that they didn't uh give you, right? So we kind of need a loop on this and to check uh that they are actually like they they are sending us all the information for the blocks we requested.

So right, this is a difficulty like the theory in theory is quite simple and there is always small difficulties in implementation and that you can see it here um okay so we have sent a request for block bodies and um so like I mentioned there is a hard size limit uh so the block bodies might not uh so we are going to wait for the message we are going to parse the block bodies and try to make sure that it's all all the information we want um and if not we just do another request and this is complete so this is how you can fetch block uh and get all the blocks information so we are all listing the part where you fetch them from peer to peer and of course you can modify this program and have it in text in whatever database you want and do whatever you want with those data and start analysis do fun things uh look for uh private key by using uh nonce vulnerabilities or follow I don't know uh influencer who are doing pump and dumps uh cool thing I'm pretty sure you have a lot of idea uh okay I'm going to show to show it to you how it works when it's at step 13 all right compelling.

And here this is working. So we can see that we are going from the top and numbers of blocks are going down. So we are connected to peer and fetching blocks for the network. Oh, we can see a code too. Yeah. So if I wanted the block 100, can I go directly or if you only want blockaders? No, 100, right? Oh yes, you could.

Yeah. If I just wanted from 100 to 200, not the same. Yes, you can also you know the house the block has you can use block hash or you can use block number actually. But yes, you definitely can. Here we are trying to fetch all the blocks, but you can definitely can. And so then the speed will just depend. Sorry. Then the the speed will just depend on sort of how many archive nodes there are in the network or like yeah. I don't I'm not even sure you need archive nodes, you just need nodes because I think all the nodes they have the blockaders and blocks information, right? Yeah, okay, but uh because this is just for yeah if if you want to reseat then you would need uh or uh person writing.

I think you you need so yeah, you just find one of those, you connect to them. And uh best is if you can find someone who is close to you, then the latency is short. Uh but it should be easier when you want to do batch, you know. This should be uh be a little bit more faster than Gson RPC. Yeah, because that then you can distribute the batch across also multiple nodes, uh instead of just being batched on one node that is okay. It's pretty cool. Yeah, this is binary data now. Uh so here we are trusting the whatever the nodes is telling us.

We don't check, right? You can uh so in this workshop no we don't check, but you can check, right? Because uh all all the blocks are linked. You can also check using uh transaction routes, so you can calculate the Merkel route with all the transactions and it's included in the headers, right? And the headers are being um linked to the um to the previous block which is linked to the previous block, and you can go down to Genesis. So you can check everything on your own once you have the information. You don't need to trust the node.

You you don't trust the node, but you still need to know that uh the block has been finalized. You need to check on the the finalized block though, correct? Whether the the Merkle root, the state root that you're yeah. Uh yeah. So you can check for reorg. Uh but I don't think I think since the merge if it's there on the execution clients, it's okay. It's not going to go away. So you're pretty sure it's not going to change. Uh but the execution client could just give you back bad blocks, like non-existent blocks if it wanted.

So like you can't like you don't you need to check the um the uh the consensus client? You need uh check from the consensus client to confirm that the block hash that you're getting back has actually been confirmed. Yeah, so I'm not that uh uh informed about how how does it work with the new consensus? But before, like for Rink Rubby, you can just check for the proof of work. But with the new consensus, uh I don't want to say uh something stupid, so I'm just going to tell you that I don't know.

All right, and if you so the workshop was a way for you to get your hand dirty and try to do something. Uh but if you don't want to actually code or anything, uh the project is open source. So it's open source indexer and it works with uh testnet, mainnet. Also we've made it work with Binance and we are looking to have it work for uh other uh other chain. We also have uh open source project, crawlers, a not crawlers to find nodes, because this is also something fans to do. Well, peer-to-peer, we just they call it peer-to-peer.

So you have a code for the Bitcoin network, and we actually have an indexer because this was the first one that I've done. I've not yet released the code open source, but I will be sure to do this uh this week. It's just a matter for me to remove uh database password. All right, thank you everyone.

Related talks