Workshop: Ethereum Transactions - #2 Decoding Input Data
Ethereum Malaysia·Sat, Oct 9, 2021, 12:00 AM
This is Part 2 in a series of workshops exploring transactions in Ethereum. Other sessions include the following topics: #1 Verifying contracts (watch here: https://www.youtube.com/watch?v=awd5kGPI1fo) #3 Event logs #4 Internal transactions #5 Execution trace Areas covered in this workshop: - Explain what function signatures are - Walk through converting between method ID & function (text to byte signature) - Walk through converting between hex & other data types (integer, string, bool, etc) - How to send & read Ethereum messages - Explore decoding calldata nested in arrays Slides: https://docs.google.com/presentation/d/1ChI_Og71lqrZkGffXq9ANHDTKnQYcBzQeLxsBE8xVLk/edit#slide=id.p Prerequisites: - Have watched Part 1: https://www.youtube.com/watch?v=awd5kGPI1fo
Transcript
okay thanks everyone for joining uh this is part two of our ethereum transactions uh workshop series uh last week uh we looked at verifying contract this week we are looking at decoding input data and chichon take it away all right hi guys welcome back uh my name is citrine for those who do not know and for those who joined the last week last week's workshop i hope you guys have fun so this week we are going to venture into another uh contract related part of ethereum mainly the method calls and hence the um the title decoding input data so without further ado let's start uh sorry i recap from last week what we did last week for those uh for the benefit of those who miss it and would like to know more last week we have successfully created and deployed a smart contract using uh three different tools remix truffle and hardhat the steps are in the video i think i believe this has been posted out in the official vl youtube so for those who would like to check it out more you can always go there after after session and we also try to uh we should look into verifying contracts on each scan and sourcify and we look at the contract read and write contract interface using uh inter-scan and how how do we do that using using eaterscan's interface so that we don't have to write codes to manually interact with the contract that's deployed and at the end of the session we also look a bit on the possible the ability to inspect the code the input data and also look at event logs for a contract that has been verified and today we are particularly interested in the input data part event logs we will do it in the next session and before i before i officially start uh for those who have questions feel free to leave them down in the chat as you did last week and i will just look at i will screen through a chat from time to time and answer your question if i'm able to all right so let's let's begin so now what what we really want to do is that we going to look at how input data look like so in i have this this is a transition that we have performed last week right from the contract we have where we thought in coven i used this example because it's something that we are familiar with so it's reset to last week's uh workshop and right at the bottom of the screen you can see that this is input data section and it's nicely written up or said hey this is the function name this is the parameter the parameter name and the method id and this long uh list of zeros and uh and then at the end and then with five so we're gonna understand uh what is this and [Music] well we all know from last week this data will only uh appear in such a form when the contract has been verified so if the contract has not been verified we will get something like this so this is essentially the input data that the user is sending to the blockchain when they are trying to interact with this contract and we are going to make sense of uh the meaning behind this thing so yeah there's a way to read it and we are going our end goal today is to be able to [Music] understand this one and we'll at the end of the session to make things a bit more fun we'll look into uh unisoft b3s and multicore i will pick up an example we'll try to decode that input data as well so for those who are more interested you can stay tuned on to the unison v3 section i won't talk about the workings of use of v3 it's just the decoding input part because unison v3 is a bit more is it's a bit a bit more technical so we'll just look at the recording pro part all right so our end goal is to understand what's the meaning of this thing right and the answer should be and the result let me see uh should be something like this cool so over here i have the input data i have the function names nicely shown to us in the scan the method id as well as the parameters that we are passing in as well as the type so yeah at the end we're trying to make sense of that oh zoom okay sorry guys oops how do i zoom i don't know oops view top left view oh okay as you can see i i have hardly used a little bit too big there's a magnifying icon uh just below the insert button where uh here um get out from the menu okay uh there's a magnifying um you see just you know insert you know to the left just below the insert button left right here okay okay yeah okay fine fine um so yeah you can go in and out is this okay this is uh not helping 100 fit is it big enough for you guys no no it's too big can i can i can't do 42 200 is fine it's okay but it's huge for me to navigate but yeah let's do 200 then uh i will tell me as i scroll up and scroll down uh this slide yeah so yeah sorry for the bit of a issue but okay uh recap input data will look like this and we will understand how does this goes to something like this and we understand how does this go to something that contains uh parameters of this data type and name okay so that's the end goal for today's workshop all right so um so let's first talk about method id what is method id now method id is actually a fancy name to say uh the the the cash check 256 of the function and its parameters and take note it's only the first four bytes okay i know that sounds more fancy so let's example example this is the sort of like a text signature it looks like the method that we are going to call right this is the name of the method and this is the type of the parameter that uh we are passing into to call this method the method id is simply the the hex the okay the partial hash listing and it will give us this thing so basically this thing this hash over here means that it's add to current number this is functioning with um with uh you in 256 type can you share the x link is that it will be easy to read uh because it's my private private docs can i show it afterwards after the session i'll share it to harifa and he can broke us to the who needs it except if it's okay for you okay nice i will show it uh let's after this it says after session and we will say and and take note that this is only a partial of the hex hence i mentioned the first four bytes so what do i mean by that okay so over here there's an example so um let's look at this this function name called a min with a with a one two three four five with five parameters uh two uins in front they address string and followed by an address and the parameter names are a b c c uh it shouldn't be c should be maybe something else each because the parent is gonna repeat maybe it's d and e and what we do to to get the method id is first we remove all the abcds and each the method that the parameter names so to say and we will get something like this right and then we apply a cachet 256 hash so for for those who are not familiar with uh hashing let's say basically we are converting this into a unique string using some crypto cryptographic calculations and this thing basically will be hashed to something like this right it's a very long looking uh string of text necessary is standard for credit 256. i'm not going to go into that but after hashing we what we are really interested in is actually the first four bytes of uh of the resultant hash so the first four bytes is actually one byte two by three bytes and four bytes df08b714 so this one will essentially be our method id right um there are reasons as to why they only take the first four bytes such as a save save a bit of gas when they call but uh that one is i won't go into too deep into that but one thing to note is that because it only takes the first four bytes of the of the uh hash there's a chance of a method name having collisions um therefore looking at this df08b 714 there is no way to know for certain that this thing means it's a main function with these parameters it could be something else that so happened coincidentally shares the same small bite but the rest of the hash it's completely different that is a possibility but because this thing is only important in in this smart contract environment the the scope of the smart contract so the possibility of a collision it's it's rather low and when you have a collision when compiling so happen maybe you have a collision function maybe you i don't know maybe you're lucky or unlucky you you generate the same first small byte when you uh select your function name your compiler will uh will fail and how it being used in uh in when you call a contract so this is an example okay i'm going to show you this this simple code first so this one has the two functions set a and set b so we know both of them will have a different method id already assuming that they don't collide which is very low likelihood and in the opcode this is a [Music] comment a code so when we first call data right the first part of the the first part will be it means that we are extracting the first four bytes and zero to four we are getting the first four bytes and the evm will have an if-else statement so if if the first one equals to uh this method id we will jump to set b and else it will jump to set a so this is a brief um overlook on our overview on how the evm uses the method my id to call the correct function and i store it from someone's article shamelessly i didn't write this and so now that we know how to generate with hang on uh i think it's better if i show an example so there is a list of uh public defending that we can use to sort of uh search for uh the method ids and it's called four pipe dot directory it's free to use it's coming an example if i were to copy this one this one because they already have this this record there right so if i copy and paste this one it will spit out um you give me the result that so happen this one has the method of view this one and take note that this this uh website that do not have all the bikes images that does not have records for all the meta ids it's just it's just the ones that people uh have contributed and uploaded to the site to use so they are the likelihood that your method id may not be uh cannot be found here okay and so to demonstrate that this thing is in fact this thing let's copy this and i have a kch256 online tool that you can use so it will oops i have to remove the spaces and then i take the first four bytes so one byte is equal to what is hexadecimal so one byte will be equivalent to two characters so one two three four you can remove the rest so uh and we have we have to add a zero x and this one will be our method id the f zero eight b seven one four and df zero eight p seven one four right that's a so that's basically how how the method id is calculated it's from the function name along with the parameters not including a partition not including the parentheses name you can name anything that you want and as long as this one is and this one are uh are same and then you make and then you and then you is making this form and then you check two five six hit and then you take the first four beats and you return into the method id all right uh so that's how we get the method id and how it is being used in an evm next up we look at input data which is slightly more interesting so uh another repeat of uh the examples that i use ago so this is an input data and now we know that the first four bytes will always be the method id then what does the rest of the remaining byte mean actually so um okay uh this one there is again uh no easy way to know the only and if if i'm only given this one over here right i wouldn't know that i wouldn't know that this is actually five because it could be it could be some other types it could be maybe um maybe maybe what what types do i have maybe uh in instead of you in because i would i want to be in other words i wouldn't be able to guess the type okay in this case it's an example but if it's more complex right i wouldn't be able to guess uh the parameters type parameter types judging using only the information i'm given here and hence we need an api api it's a kind of recipe that tells us that tells us how the function and the parameters looks like and from api it's something that we looked at in last week's workshop so that is very important when you interact with your contract because without that right you wouldn't know how to translate your user with data to uh this encoded form so okay and take note that each input data will have a length of 32 bytes and 32 bytes is a 64 characters because it's hexadecimal okay next so looking at the previous example we know that it's already a uni-256 right so the zero zero zero zero a lot of zeros and five will be converted to zero x five i if i use the hash the hexadecimal to a decimal converter i will get that my underscore 2 at is actually 5. so that's a simple look at how you decode a u in uh parameter type now the same concept applies to other other addresses other types which includes addresses boolean but arrays for example byte strings or maybe uh you in will be a bit different okay it's a bit different and we will look into it and oh sometimes if you see because this is unsigned integer so if you see your integer right you need to use uh this thing called a tool's complement to uh to convert it that means you cannot you cannot assume that this thing is a five anymore you have to you have to apply the tools complement to convert the bytes to integer uh this is a calculator which you can use two component is a way to handle negative numbers in the in computer languages for computer to read yeah negative numbers okay um let's try another example now i have a slightly more complex example the function name is test function and i have one two three i have three three parameters the first one is uh you in256 address and bool and the input data that i have now it's this long text over here so long very long text i'm going to don't mind me i'm going to just make it smaller for just this on this slide okay and if i do not have this let's say if i decide to delete this oops let's see if i will delete this there's no way for me to to decode this because this thing could be it could be it could be we want to be sure that this is the type address right it could be something else it could be maybe a string maybe who knows oops okay so the first thing we do is we split up the method id which is the first four byte so we remove this part and then we separate the remaining characters over here by 32 bytes so the first 32 byte will be here until here so it's this one zero three the second one will be here to uh to maybe uh wait i'm trying to find here it's a answer for it i've already done it here and the last one is uh this one because it's okay and and then we know that we know that the first parameter we have is three and it's a type you in we can let's do it for the sake of a demo hex to decimal converter so is 0x3 convert it will be 3. so the first parameter that we have over here that the user inputted was a 3 and address address is is a 20 addresses has a fixed length of 20 bytes so uh the input data will append the additional 12 yeah 12 bytes with zeros and so the rest of it will automatically be the address the address so in this case the address would be 0x 80b 869916 and uh so and so forth boolean is only 0 and 1. so in this case is 0 and therefore it's a it's a false so from there we can see that the actual data that was being passed in was 3 0x a0 b 48 and false okay so a quick okay so everyone okay yeah awesome so a quick recap we need to know it's important for us to understand uh to have the contract api that includes the recipe for the type of parameters that uh that the user call and with that we can conveniently say that this one it will be decoded to uh the the user regular types so that's how uh that's how we do it okay uh moving on we'll be looking at um bike stay too bikes will be a bit different now uh notice that every before that right this and these and this one if it's true you'll be hit one over here yeah i'll call a little endian uh you don't have to remember the name it's just that the the uh the values that we are interested in will start from the end right you'll start from the right so this one is start from the right this one starts right and starts right but for uh types like bikes it'll be different it's it starts from the left they call it the big endian don't worry about the other name just to bear in mind that this one starts from from the left so in other words um this this this function with this type and this input type let's split them at the id out method idl uh or copy wrongly uh and this abcd this one will be this one will be the byte and it starts from the from the left so we can just remove all the zeros behind and so it will be 0x a b c d e f a b c d let's know that bytes will be different and arrays and bytes and strings are also slightly different um from here we can see that um i have an input of one and two and uh this is the type right is u into five six and this this square square bracket basically means that we are it accepts uh the type of an array and it's it's longer than uh and what we expected right because there's only two numbers we expect it to only have maybe maybe a zero and one but we have zero one two three so what is going on over here now um evm has a different way of letting the [Music] letting letting itself knows that hey this is an array first up if it's an array um the first 32 bytes here right will be converted to you in and it becomes 32 and this this this uh 20 basically basically means 32 in the in you in decimal so because it's in hex right so we have to convert it to switch type 2 and the second 30 32 32 bytes will be two here and it means the length of the array uh i'll talk about this later and the third and the fourth will be the the data that we're interested in and what do you mean by 32 over here it means that we have to to get the to get to the array we have to ops we have to move offset it by 32 bytes so the length of the array will appear 32 bucks later so from here 32 by 3 will be here so we know that hey this is our the beginning of the array and the races and this one says it's two that means we will be expecting uh a length of two um arrayed at so length of two already so in this case this one will be the first one and this one will be the second one so um arrays will be tricky it has these two parts it will tell us where to start the array at and it will tell us the length of the array and uh because this is two leg of two so we have two uh input data that we can be expecting so this will be one and this will be two so we are arrays and bytes and strings are similar uh let's look at points and and let's say that i have another function it's test and uh i accept parameters with a type of bytes this one is a typo and this is the input input data right and this one is also typo and the first four bytes over here will be the method id so let's let's ignore that and then we separate this thing out into 32 bytes each so this one will be 32 bytes followed by this one and followed by this one okay so i've formatted it for you over here and bytes the first 32 bit two to two bytes will will also be the starting point starting uh bytes that that we are interested in so in this case is 20 so we will start 32 by later which is um here and this will be one so it means that um you're expecting uh one bite length uh bytes and one by length basically basically one byte basically has a two basically represented by two hexadecimal alphabets and so we can this one zero a basically means a in a zero x a in a byte form the string is similar similar to this to this thing it's just that the final outcome right we have to convert it to a utf uh so we can rely on this online tool we can write this on a2 and then we have we just convert 0xa to uh utf-8 yeah oops it's not okay uh yeah fine uh you should convert but i don't know maybe i typed the wrong wrong thing but it's fine so yeah for string we just need to convert this convert this to utf-8 and then uh it will show the the string that we are interested in but it will still follow this format this one will be the first sprite second byte third by and this one will reflect the length of the bytes that follows and if the bytes and strings are too long like for example it's more than 32 bytes we will have another new another new new set of 32 bytes to describe the uh yeah okay to describe the to this two to three more datas and this one reflect details like how long will this entire thing be here so yeah this is how a bite set string will work so yeah basically i covered most of the types and some of them are somewhat a bit more confusing than the rest and before i proceed right uh any questions why would smart contract use type instead of you in or in because sometimes you in and in they can't represent a lot of things right um bytes can do a lot of things for example you can convert it we'll look at example for unisof v3 that accepts an array of bytes and from there they will format it out to the respective type so that's one of the examples they can format to maybe address can format to string you can put put together a long list of things and it's also a bit more uh efficient to say a bit more guest saving if i if i if i'm right so okay so finally let's look at um unisof b3 multicore contract and this is an example that i that i copied so that i don't i don't forget to find and if you look at the input data section right um let's let's look at the contract here we're actually saying um we have this method method method column that shows uh the method that we're calling but if we look at the method only everything is calling multicore uh equal the transaction correct will be doing different things but the main method that is calling will be multi-core why uh because uniform b3 uses a library it's called the multiple library and users will pass in a user users we can interact with a couple of functions in the same transaction by by doing this so if you are like maybe swapping and maybe refunding if you're doing interrupt one try things for you and you'll use this method and they will put what to call inside this method to execute it in one transaction so you don't have to like call two times and maybe the price will change and stuff like that okay um yeah so here's the part that we're interested in right it's calling a multi-core and uh also an original this is the original uh original code i'm gonna copy it to notepad where's my notepad here okay actually i'm not going to complete notepad sorry guys i am going to use this thing called decode textbitter it's a very helpful tool that helped me helps me to decode you see okay so we know that the first four bytes it's basically the method id right so we just remove that one two three four just throw this away and the week for the remaining uh text we just split it by 32 points so because um one byte is basically two hexadecimal characters i'm going to split it by 64 and i'm just split and yeah there you go uh this is the nicely uh formatted stuff for us so now let's let's look at what it really means um for that let's we need to know the the function the parameters type that is passing in so it's bytes array of bytes so this thing will be an array of bytes so we know that if we know that for an array the first thing basically means the the the number of bytes to skip so it's 20 so 20 will be 32 bytes so we have to skip skip this one by 32 bytes and then this one will be the length it will be length of two right so we can expect um we can expect two bytes two elem uh two element bytes has been passed into the array and these two will be will be the the byte okay but what is going on here like it shouldn't end over here um what are the rest of these things now remember that we are handling bytes so bytes if you recall from here right once we have this this format is something like array but you can think of it as an array in an array so this one will basically also be the pointer will be the be the offset you offset by 0x40 so let's convert it to hexa x2 [Music] so we will offset by two two columns one column two column okay we'll start here and the next one because it's length two right and we expect two bytes at the passing line this will be the first part this would be the second byte the next one one e0 will be sorry guys uh if a bit more technical feel free to uh put your questions down in the chat so i can under uh explain them any clearer so we offset him by 4 680 bytes okay um so if we look at the first one this one is uh 64.
so one two so this one will be the starting of our first alpha spike and it has a length of 0x164 which is uh 250 56 bytes so the first 256 bytes is something that we're interested in right and this is obviously um [Music] more than 360 60 264 bytes so it will stretch out to the second group of 30 34 32 and again stretch out to another two straight 32 and then until it's it's here so let's perform a calculation how many 356 divided by eleven point eleven point one so it's gonna be twelve so it was like it's very confusing uh one six four here one two three four five six seven eight nine ten eleven twelve okay one two three four five six eight no no sorry wrong one oh sorry one two three four five six seven 8 9 10 11 12. oh yeah that's right here so this stretch of data will be the second byte that we're interested in okay and what about these two now remember that um previously right we have two we have two offsets one is this one which is the first stretch of data this one is the second one that we're interested in and if you were to convert one e0 4 8 0 and we so we offset by 15. one two three four five oops uh 1 2 3 4 5 6 7 8 9 10 eleven twelve thirteen fourteen eight no wrong sorry guys uh one two three four five six seven eight nine ten seven twelve thirteen eight what am i doing [Music] here this one is let me figure this out sort of got confused confuse myself one two three four five six seven eight nine ten one two three four five yeah then i calculated wrongly uh yes so by offsetting it to 15 right we'll get here we'll get to here so this one will be the second element that we're interested in and because the length of this is four so this one will only be four bytes and there is no need to expand it beyond 32 bytes so basically in other words it's calling it has two bytes right the multi-core that we are interested in has uh two bytes and each byte and if we were to look at this right the first bike will have uh this one the second bike is uh here so yeah so this is and this second bike is easier to look we look at it first it only has length of four bytes so one two 2 1 2 2 1 0 e 8 a will be then be the method id of the function it's calling now why is it the method id of the function it's calling well because after decoding the data into its respective uh bytes form uh multi-core will call it delegate call and then navigate call will automatically just look for this thing right treat this as an input data and then we will call the function again and therefore these first four bytes one two three four will be the method id for the function min and the rest you can decode it as we did just now to get the respective values just like how interscan did it over here in this case it's a bit shorter because there are no inputs because this one has no parameters so there's no need for input so method id in this case will be suffice the function is called a refund eth so so um so doing it manually it's uh it's hard like as you can see just how i did a couple of mistakes counting in front of the audience but it's possible and this is how um if you follow us who are interested in reading more details so this is how you do it you you you get the abi and then you follow the format and then you get your results and yeah that's how you that's how the evm read it so it's for machine to read enough for humans to read that pretty much concludes the session it's a bit short but i hope it's not too confusing any questions um can you walk through uh an example of a transaction let's say on it sky a random random transition yeah maybe not multi-core like if it can be too confusing uh let's see if this is a contract maybe you can yeah this one do you want to don't want to look at this one yeah sure okay okay i'm doing it live i'm not noticing before so um marry me guys so okay first thing i'm going to complete to my notepad it's going to be very long and the first we can remove the first four bytes one two three four because that's going to be a method id just remove that and the rest of the it we can separate it by uh the two bits so let's do it my trusty text fitter split okay so the [Music] you know it's a weapon we get free stuff um so this is the the remaining input data with uh 32 32 speed by 32 bytes so this will be the first two the f32 and so on okay third thing that we need to do is that we need to know the types that we are going to expect right uh over here i'm gonna i'm gonna cheat i'm gonna look at this type so it's the first one is a ui you in two five six seconds you you into five six one other one is an array of address fourth one is an address and fifth one is a new in two five six so basically there are a lot of you in two five six and uh one array and one address so it's not going to be too difficult thankfully so let's look at the first two two into five six so these two is going to be the let's convert this to u into classics i mean yeah okay for that we use this one correct so the first um so the first input that the user has inputted to by calling this contract is this long number judging from this one right the second one will be this one remember to always append a 0x to this thing it'll be this one so from here we know that the amount in is uh it's forty four three zero something and the minimum amount minimum amount minimum i think it's pretty unique yeah it is um the user expects to have a minimum amount of uh this number of uh tokens remember uh if we have to uh normal we have to divide it by the decimal places um it really depends on the contract that we're directing right uh i think this is i'm gonna cheat it's i don't know i don't know that's focus for food so i don't know if it's 18 decimal place or some other things okay uh what do you do with the decoded data for your smart contract development data mining uh what do you mean what you just can do or what what do i do personally [Music] and sometimes if i want to know like what the user call or if i want to call the the contract uh manually without interacting with anything i would just look at this uh let's look at this and try to pick this core this is it's basically not very functional it's more on understanding how it works so you can understand how the contract works uh by decoding this we know the input that is being passed into the contract and to understand how the contract works right we have to look at the contract code and then we we play each step so we know that uh the user is inputting like this kind of stuff and we look at the contract code we we can find it i'm going to copy this show you the contract code find this here one sec right here so the user is basically calling this function uh uh it's an interface uh yeah this function right and then from here we look at uh well where is this one being used uh it says that we are safe transferring among one so about out min so uh we get it from here no no one might want it we get it from we checked for the recording and so and so forth so if you would really like to know how the how does the input parameters interact with the contract code we have to come into the code and just understand the logic of the code and as you can see uh this one over here they call some other contracts so you need to jump on to maybe transfer helper to look at what does a safe transfer from uh do so even as a non-death i could use the function to interact with the contract directly uh yes because this is is calling decoding the input data itself is a hassle so encoding it will also be a hassle the easiest way to interact it directly is to use scans uh read and write contract uh functionality we have already done it for you behind you just need to type in the user readable uh text or make close of the contract uh yes you can just complete copy this and uh and this deploy that's what a lot of people that's all what a lot of people does right uh and for sushi swap they copy this one and stuff some people just copy this without even bother changing the contract name yeah you can make clones easily because it's public it's public data right but whether people would like to want to use it or not uh it's another story but you can clone this and you can sneakily change some of the code too okay not not recommended uh not good political but you can okay uh sorry now we stop at address array path so this is a bit tricky it's an array right but we we just have to bear in mind that the the format of an array sounds very useful to reverse yes uh address array path so let's look at our text speaker say this one right and because i know this array right so this one i know that it's going to be offset by a0 so what's a 0 as you can see i'm not very good at converting a hex to decimal in my head 160 160 and i'm also not very good at dividing stuff so i need to do this uh i don't need something i want so it's going to occur by five arrays okay five so now we look at this one two three four eight no five one two three four five yeah five here you know it can't be right one two three it should be here oh why is it here uh yeah i complete something wrong let's try again no uh divide by 32 x5 anyway ignore that embarrassing uh and one two this one okay it will start from here and this one will have a length of two which tells us that uh this one and this one are the arrays that we're interested in and because they are addresses right we can just get this thing and put a 0x in front of it and then it will be a address so because this is the path and it's really sword i already know that the functional path is to uh is to get is to define the hops that we want uh in this so we are just directly swapping from this one to this one and this one i know from uh from experience that this is a weft so the user is transferring token chopping green token and west token okay uh let's let's look at the other two parameters address and deadline so the next one one two three four this one will be the address well this is a very unique address uh this is a lot of zeros in the address i need to get the length uh this is annoying it's 32 bytes so i need to minus by 12 points one two three four five six seven eight nine ten eleven twelve is it correct i don't know let's try oops uh wrong one you want them let's try again uh i should do this string length before uh wait so long uh country is 40 so i'm gonna manage one two three four five six eight nine ten so give us the let's look at what address 2 it's transferring to this guy right oh yeah this is what happens uh if you do it live sorry guys oh wait did i did i did i do things wrongly oh sorry guys um [Music] i read the wrong field yes thanks yes it's a third field this one this one uh yes you guys are right this is these are the few yeah so you're just really using this and then yeah you're right thanks and the last one over here it's the no no sorry this one was telling uh this one we just have to convey it to you in right do you in and this will be the timestamp the deadline for uh for the call transaction to expire so yeah um is how how we would understand the this one from its functioning unit swap from its parameter uh okay can change the date to normal here so because deep is is always in [Music] it's always in the usd ut utc i can convert to human readability so that means this transaction will expire at um june 19 uh five to two pm malaysian time so it makes i haven't haven't haven't expired so that's why it's successful yeah okay that's yeah that's a true of the example transaction um so um what if there is an unverified uh contract that's being interrupted um for a verified contract we could only guess um because we don't have the abi right if we somehow could know the abi of i mean we if we somehow could know the parameters of the function we could use the same and probably the same technique to decode to human readable input data but generally i'm verified under contracts the api is not known so there is no 100 way to say that hey this is going to be the final this is going to be the actual uh input that the user has um inputted we can only guess but it's not hundred percent because we may get stronger something some some things will be decoded wrongly and stuff we could guess we could guess um so uh will you be showing event logs as well uh we'll be next week i'll leave it for next week and um can you run through the ethereum messages like like sending string um oh okay um yes i do do you have the example translations oh wait um can you go to vb address uh scroll down oops sorry oh yours okay okay um i think there's one that was sent to uh zero zero zero uh dead listen yeah is it this one yes uh what this one so what harif was mentioning was um how do users include input text the text into an atm transaction so how indeed uh for this i'm gonna use uh metamask so uh in metamask there's an advanced feature that we can uh i'm gonna be careful here to not show home advanced feature and we can show hex data and we can uh toggle toggle this this uh this button here off and on i've already on it so if you toggle that right what happens is what happens is that if we try to send a transaction let's say i'm going to transfer to wherever to myself see and now i have a hex data column over here so previously um if you don't you don't see it if you if you don't you don't uh turn it on so this column is something that we will use to maybe generate the same message right so uh let's maybe let me be a bit cheeky to just copy this thing and uh because this is a utf 8 string in ethereum is utf-8 so we convert utf-8 to hex [Music] yeah this is two again hello here okay uh but i i need to split the the zero x out uh there's a way to do this utf-8 to bite binary [Music] oh you again uh i don't know i don't think this will work basically this one will work i just need to manually remove the 0x space because it's too long so i'm going to pick a short short short sentence i've decided i think that is a good way yeah i'm happy with that so let's remove this one i can't even copy up okay let's move obviously there are better ways to do this i'm just prepared okay copy and send to myself however [Music] okay i go to coven let's give it a bit of a time i'm gonna expand refresh this thing hmm what's the slow harry potter not enough validators or minus one kovan probably it's okay so we look at the input data and then we decode it so i've decided so uh that's how you send an input data in a transaction using metamask yep so i think we're at 5 32 uh we're a bit more than the one hour that was slotted are there any questions from anyone uh sure seems like we could scrap the code data for insights do you think it's possible uh scrap decoder data uh well because everything is in the blockchain anyway so you can actually do it anyway unless you want to scrap interstate data that's what you're referring to you don't need to scrap you really don't need to scrap it's available perfectly let me let me show you let me show you that it's available publicly if you want to if i interested in this guy right for example you know you don't need to script you can just export as csv and then you give you all the data that you want so don't need to scrape anything just export what's the api for this i was looking at the scan libraries a few days ago but i don't see this specific api called no i just want to get the i just want you to provide to me in the json the yes adjacent field do you do you have the api already you mean uh how do you do this it scan okay uh i can answer this as well don't do this manually because it doesn't relies on web3 web3 has a library that we can use let's pass in the api and pass in the input data you automatically speed this thing up and i just format it into the format okay so yeah uh of course you can write your own but uh rap3 has provided a nice library which i can use so let's use it oh uh donate api right donate because this thing can offline so you don't have to call we have to call an online source to get the data just to offline this is the level library uh can i explain how do we trace the method id to the specific function from the contract uh how if i had to say a question correctly right you want to know if a method id okay you want to know if this method id represents claim right uh what am i doing how do i track so number one you look at the you look at the contract api you convert every of the functions over there to the four bytes format and then you you see which one it matches because that's how evm does it as well so okay nice i have a question about applications again so we did talked about it a little bit earlier but i was wondering um knowing what we know today right or what are the other applications we can build from this information um you talked a bit about 32 by the website that helps you quickly given the id you can you can see you know what are the no no no no this one the the 32 the four by directory yes that's the one but that's something that if i know the method id i can probably look up what it does without actually knowing anything further inside it i need the api for everything else right but is there anything from today's information that helps me understand how to optimize my my methods for example or if you want to occupy a method something that i read was um [Music] if that there is a possib if there's a there's something if there's something you can do right always use um always use if you can always use bytes instead of bites that bites this one because if you understand how uh how does bites and bites this sort of works right this will append the the you know offset by how many how many uh say by how many uh bytes and at the length you actually passing in more data to to uh to function and this one requires more gas to execute right uh unfortunately uh for input data they don't pack the bytes so if anything will be 32 bytes and another thing that i've read is that um [Music] data with more zeros are cheaper so for example if you're calling like maybe maybe these are you this is the maybe this function has a the type of u in 256 right and another function has the type of um in 256 so say yeah and this one we are only allowing user to maybe pass in like maybe one two one to ten it's a small number so maybe the user passes one so be as usual whatever one right uh but if if you're allowing if you're allowing um am i am i doing my correctly okay and then if you are allowing users to pass in this one right i think one will still be the same result but if he's passing negative one it will be f f f f i think f all the way because it's too compliment so if i'm not mistaken f will be more expensive to will be more gas expensive than uh calling zero more zeros will be cheaper if i'm not mistaken so i'm not sure if this is what you mean yeah i get that but uh i'll probably look into it a little bit further um one one more last question about about that but just knowing the method id knowing the input data doesn't tell me what the method actually does i need to yeah it doesn't right it doesn't uh yeah it's yeah it's it's basically more on a developer's trying to number one uh get more information on how things works yeah number two if you are building something that maybe tracks the method id if uh you can do that yeah basically for normal users i wouldn't expect much of a use case right so so without the api or having access to the source code i can't actually go any further uh yes you cannot be 100 certain that uh the function looks like this or that yeah okay okay all right thanks yeah so it's more like like like like like you point like like what you pointed out it's more like a it's more fun there's not much uh actual use case for normal eq users right thanks yeah um there are uh i think the like uh especially before the mev stuff uh became big like all these uh bought priority guest auction bot makers uh would actually look at um obviously the contracts are not verified because they want to like keep it to themselves but someone would actually uh like try and interpret what's being done and basically uh create and copy out that whatever functions that those bots had yeah so probably reverse engineering stuff but as you can see as you see it's going to be it's not going to be easier but yeah with time maybe you can do it and with a lot of money at stake yeah okay so i think that's a bit more than the time that we planned we can end the call today and for next week next session uh chichon what will we be covering uh event logs we'll be talking about event logs and and uh relevant items around that uh i i assume uh topic zero and so on just right this one okay thanks thanks for joining guys and we will see you next week thank you for having me again uh thank you thank you for spending your time on this workshop and that's arif uh for opportunity
Automatic transcript — names and jargon may be misspelled.