New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Visualizing Swarm Hashes, Node Addresses and Neighborhoods

SwarmWed, Oct 9, 2024, 12:00 AM

πŸ“– For more information on this workshop, you can dive into the Docs: https://docs.ethswarm.org/docs Did you know that there are multiple types of chunks? πŸ˜ŽπŸ‘‰ https://docs.ethswarm.org/docs/develo... ⏰ -- Timeline - ⏰ 00:00 Byte representation of a chunk 00:36 Hash functions 01:37 Sample text breakdown into 1 chunk 02:17 Chunk Address 03:13 Root Hash 03:18 Calculations for the Final Hash 03:51 Real World Example

Transcript

this here is 4,096 bytes so this must be a swarm chunk but it's not why it is true that one swarm chunk can hold up to 4,096 bytes of data it actually has an extra 8 bytes the span the span is a number stored in 8 bytes which tells us how much data the chunk has not only does it make one chunk 8 bytes longer but it also has an effect on the content address of a chunk before we make sense of these Concepts let's visit hash functions first a hash function takes arbitary data and turns it into a fixed length output known as the hash for example we can feed the hash function the text hello and get this if we feed it hello again we get the same hash what if we change only a small detail such as turning the H to uppercase will the hash change only slight lightly as you can see no we received a completely different outcome this property of hashing makes it secure and private and maps all distinct data to a uniformly distributed hash space Also hashing is one way only unlike encryption what if we Feit the hash function some huge data the output is still only 32 bytes because of its fixed length output property in form and usually in the industry we use the kachak 256 hash function remember this name this here is a real swarm chunk it has 4,096 BYT space along with the span on the top correctly displaying zero as we have not written anything to it the 4,096 bytes are grouped into segments of 32 bytes there are 128 of them as 32 * 128 is 4,096 this will be important in a minute let's fill it up with some text Data first as we are writing it you can see the span incrementing one by one as we are using up those bite slots now let's talk about the elephant in the room the address of the chunk as you know swarm chunks are content addressed meaning their address is deterministic based on their content and they are located using their address how can V or how does B calculate the corresponding Address given some data like we have here let's bring in the kachak 256 hash function we discussed earlier and calculate the so-called BMT root hash of this chunk I will show you the process it's not that bad first we hash every segment with its pair which is the one after it that is we feed the katchup 256 with the bytes in the first segment and the bytes in the second segment we repeat this step until there is only one hash left once we are down to one we have the root hash but is it the address of the chunk not yet but we are almost there let's convert the span the length of the chunk to a little ndn unsigned in 64 it is one to represent a number in binary format it is no longer readable for us Mortals but it's still the same number finally we hash together the span and the root hash which gets us down to only one hash again the final hash this is the address of the chunk it's EF something ending with 7A don't take my word for it let's upload the original text to a live B node and check what hash we get also we have something ending with 7 a thank you for your attention

Automatic transcript β€” names and jargon may be misspelled.