# The Challenge of Implementing Solidity Stack Traces by Patricio Palladino (Devcon5)

- Speakers: [Patricio Palladino](https://streameth.org/speakers/patricio-palladino)
- Channel: [Devcon](https://streameth.org/devcon)
- Date: 2020-10-09
- Duration: 24:29
- Topics: blockchain, smart contracts, distributed ledger, ethereum, Science & Technology
- Watch: https://streameth.org/watch/yt-24O8cDDGDQI
- YouTube: https://www.youtube.com/watch?v=24O8cDDGDQI

## Description

Visit the https://archive.devcon.org/ to gain access to the entire library of Devcon talks with the ease of filtering, playlists, personalized suggestions, decentralized access on IPFS and more.
https://archive.devcon.org/archive/watch/5/the-challenge-of-implementing-solidity-stack-traces

Debugging is an unavoidable phase of the software development cycle, and the most frustrating and productivity wasting part of developing smart contracts. The essential tools that a programmer would use to debug code manually in a mature platform are missing or unstable in Ethereum or are unstable. These are easy debug logging (e.g. console.log) and stack traces. In addition, smart contracts development presents extra challenges, like testing code and smart contract code being written in different programming languages.
In this presentation, we'll shed some light on how stack traces work in other platforms and the challenges we had to solve for building them for Solidity in Buidler. These include identifying the code behind each contract address, identifying the functions in the stack, recognizing Solidity's compilation patterns to improve error messages, and how to display them from your JavaScript tests.

Speaker(s): Patricio Palladino
Skill level: Advanced
Track: Developer Infrastructure
Keywords: technical

Follow us: https://twitter.com/efdevcon, https://twitter.com/ethereum
Learn more about devcon: https://www.devcon.org/
Learn more about ethereum: https://ethereum.org/ 

Devcon is the Ethereum conference for developers, researchers, thinkers, and makers. 
Devcon 5 was held in Osaka, Japan on Oct 8 - 11, 2019.
Devcon is organized and presented by the Ethereum Foundation, with the support of our sponsors. To find out more, please visit https://ethereum.foundation/

## Transcript

[Applause] oh no it laughs where we this to decode Riddler it's a smackdown tech development plus running a million recently via India I'd say test development Network hey I mean a development network i we which has these very distant each other whatever you've done such an awkward phase it generates a salinity spectra and this presentation is for me about how we do though but going back to the beginning let's talk a little bit about possible for me this starting people to submit seventeen I would say freakin maximal East recovery maximally smugly and the work my friends money convinced me to join them to build their first stuff and I knew nothing about a few I began reading about me were super excited to gain about Victor and started believe this stuff I was in charge of the smart contacts so I knew nothing about solidity just doing some front-end stuff and then the vacay where I finally had a smart contacts to integrating and the first thing I try to do was the most basic thing just Cindy to contract from my UI and I was super happy about that but polygon was in maniago what the welcome I was sure that I was using the random binary how can I come in Malevich ooh I wasn't doing anything with of course I wasn't modifying the contract just compile execute invalid Oh nonsense so I must have Spain at least one day when to figure out what was going on and leave my friend I move again came and Tommy OH everything ok ever since then this is how I trade whenever like I mean we time I develop my own techniques like that which transaction was fading this was just who make these random checks of solidity as we run everything until I eventually figure out what was going on but I told me that it will eventually get better and if it goes a little better we got remain resource super useful but you know we were comfortable enough with the speed of improvement so we started working on building our development tool and last week we learn we launched what we call integrated charlie and so needs exceptions these are us neatly chocolates that don't mind both yourselves three strike start raise up until the moment that you call it into your contract and on top of that you get invited solidity stack trace so in a single place you get the entire picture of one your face explaining you get like up until which point in your destiny faith and then you get where you're contacting fail and also it recognizes the bunch of common errors in solidity like calling a function and that doesn't exist and you give you a precise error message on those cases instead of just reacting without reason it takes you back to college faction that lesson exists so how do we do that before going into that it's totally bit about how stock prices work on a normal environment so let's say that you are banging a sigma space program just a binary whenever you have a structure that everyone knows this fact or goes back trust and whenever you go into a faction a new stack frame is pretty it's just it's local governments we match up metadata and whenever you return from a fracture it's not frame is popped from the stack and if these program needs to see me right session in which size start the process that it's going to stack up running its gifts poking up stack frames one by one until it gets into a narrow fender and I know that super easy it's the same program that it's responsible for doing this black frame so some but the thing is that incivility in the image and we don't cover is a good side why I have no idea but it's that way there's some people who posted in VIP to try an act request that in the EVM I don't know who the yaar and I don't know this type of fun yeah D but I think it's a super mega will pay for I hope that Steve Sunday and the other problem is gas so whichever language you can you can generate extra code or extra metal a metal about just to do things like stack traces but you pay every single local that you execute so solely this kind of first to Uranus as small vital as possible so things like meta meta for stacktrace doesn't seem to belong there so that process to generate the stock ways externally you just you're only focused be an external observer of the IBM and sank Al Motta VM execution in today's reading sources and what does this mean that you trace you execute your contacts twisty be a trend in this page this get at least of of course the great city then you have to do lots and lots of things to reconstruct the solidity semantics so our first challenge was how to get from of codes to solidity hey when you compile is my contact you will be done about words between those things there are five phones so I don't suggest a list of instructions not much and let me for each my to yourself how I saw smoke and I saw smoke the same option that they see a little bit about divided Road it's a Scots in upset names of five the maps into a chunk of refine a that generated that group and then it has this sometimes being that we talk about that later but okay this is super useful and without these women nothing but the Bellamy side these super long live we need to have a more cement the mortgage of a theme so from the vehicle we want to be able to get which country belongs to all of their factions is very our external internal their selectors everything with which source where they define no I mean I don't know I think this doesn't look like car like her but because probably one of the most challenging things because you have to I mean given the output of the compiler and this really equal and then you have to recreate lots of lovely a from the compiler just to mimic what it does too you are actually creating a movie that maps what led uses so for example very silly plot of a function some CC we use that to take into consideration all the different teachers from solidity I'll show you that computer select of this supercar okay so if we have the Smallville the next thing is to record start liquefied and this is the easiest part is a chemical study in the area but you have a new VM and you can create your own perspective shot suspect so when you execute is my contact you save the list of codes the garage secure that's the median trace and you inspect by by by iterating and whatever you find the shell here you pay attention to that junk type thing the the sauce pot give you what what's in there is whether if this was a shot into a function a return or like anything so it's easy if you go into a shot if your family's calling in with faction you push that function in your into your stack if your son is every time you papa fighter and that's it I mean some see see there's some complications because there's things like modifiers that are in actual factions but today we wanted to show them on our stack traces so we have some special cases for thing like that just to know make the lights of developers easier because I know a few shots go to a function that it's on younger you may end up subscribing on younger and not win fights over Scott hey there a bathroom that creating equal step is pretty easy so next challenge external coils well that's a number of equal segments in fact a super simplification because they be is very weird machine wherever you have to do an external that's called the net goal or one of those the semantics of that it's but you have to create another Vivienne in MDM and you execute they are the other contract so in fact it's basically VMs a reclusive thing so you get the list of books that were executed happen to happen till it's tyrannical good and then you get an added price and then some of God's continued and of course this other place besides my can also have an external cold so it said it's in a reclusive thing by Nature so yes creating the ice bag for each of these places individually is very easy but then you come then you need some combine them because they have such different executions with different stock phrases and how do you combine them but it depends in the pencil on what Rana the smart contact do if the external college face so most of films specially if you are in doing anything low-level with just over the Arab and eventually we went a transaction but you have to detect that because samples just over a loss and ignore me and in the case if we ever lose forward that means that you have to combine the stack traces like Matheny some crowd I keep going because maybe you are stealing a button when an external coil and you might have to makes me think multiple multiple times but that's fine I mean we lots of logic to detect of spaces but once it's time we got step closer another challenge and this is also a big one is recognizing which contracts are you running because up until now it was assuming that I knew which my contact I was looking at but that's not the case when you are running lots of tests with me to be smart contracts usually have a mediator execuse chance of Blackrock and that bytecode be left with my contact but purity will read out which one is not that easy for it I conjure there are two different by tooth generated work for the cranium and the other one for running it on run time I mean it's by Pope and recognizing the plague like Oh can be very easy especially if you don't use libraries such an exact match you just search for it and that's C but the problem is that when you use libraries when you link libraries you are actually modified divided book you just have to add another way somewhere in the white book and also when you are deployed in is no contact you are also modifying the Bible because you are appending its parents at the end of it so the exact the exact match search thing doesn't work but really is to create a modified right let's you said for these railroads it's a kind of tricky thing infinitives we created a canonical representation of which by toast by zeroing out where the places where addresses are going to be played they use a presentation to say the the micro movement that we talked about before and then when you are when you're executing a battle in the VA you don't know which model it belongs to you just set it on the right if you very much you're not that's fine but if you don't there are two possibilities in my shop God's talk because the next by a is the beginning of the balance of a constructor and if that's the case you can is that no this a casa constructor associated and use that but if not you are probably stuck because of a library that broadly and you have the normalized version of fee associated to the price so what we do there is to check out the descendants from the know figure out which are being used use libraries and no more time try to normalize our by talk as if it were and one of those and we run the sir we run the search and that works because some issues and you can use things like normal price you see record or things like that but after some work we got this working and we were lucky because we saw that this was the last missing piece a to get stock prices so we started doing some integration taste everything work great for some time because then we started doing crazy things with your comics my contacts and with your of the most painful things I just not much by solidity so I know I told you that for every bite book for for every of code you get the source mob of and that's true but some of them mean nothing they have us know the SS they are to keep the indexes sink but maybe they shall find meaningful that that means this thing comes from salinity so the I mean we could have stopped there because you kind of got this like crazy and up to support you have established and if your uses we're actually you see prevent require it like that they have the entire thing but you know a great developer experience means going the extra mile to get that very little message or to get done info to your youth to your usage just amazing spirit so what we did was compiled lots and lots of contracts we we're error conditions and just look at the are vital for weeks I mean it's every food thing to do especially the beginning but then you get used to it and you start recognizing the defender Rock patterns that solidly generates once you have three certain that you can recognize them by chance you can codify that in Sanskrit just repeat the same thing and detecting the thing is that you you may over feel a little bit too much on the part on how you recognize the patterns so you have to create some loosely Lucy Henry speaks you can't just look at the actual codes the traditional rates because that may change from version to version you have to do things a little bit more flexible so I will every sticks are things like okay this my contact fell in a knob cornice the map okay so let's look at the latest map source code it um things like that you know maybe I I know it's a thing work like that I with superglue see heuristics but that also means that they can go wrong so what we did was create a hold on us oh you need my sleep a for especially for this part of living a eventually you are working correctly so our final challenge how do we show the simple because so far it's just built a structure or registration and we need to show it to the user so one of the ideas we had was just to create a mocha report a report this is the UI that happens to be shown when your best faith and that person I said you have a friend maybe to come to mocha because we labium doesn't start work on mocha but just run everywhere no runs and also we don't want to die Dylan to mocha for example some guy from came in to say hi and they are using for trying to use being with chest so they need mocha would felt like a failure and I thing is that we really wanted to show these silly these actresses in the context of shops build because before your destruction fail you probably secure a whole lot of five things mostly you saw speak to set up the smile contact in a particular stage but make it fail so we will need to take that into account where we live was using some not so well-known but very well implemented and supported via API that lets you create stack traces as you wish so we get we get respect we can expect raise up until the point where you started executing the idea you start executing your contract and combine that with the solid district race so that's how we got this result that I saw at the beginning this is just a short section which we have you some speed frames the cold salida stacktrace and in automatically generated arrow that was recognized with one of loves every six so how can you use this you just have to install a it has like is for most everything so here you see toffee for toffee fine what will you just instantly place great a super simple configuration file rerun your taste and you can stack traces so that's it I just wanted to say thank you to the people who supported easy for some people have the yeah and mostly who left you GST Sydenham chorea who can be super careful and well my friends who support me when I was crazy with this [Applause]
