Wake Framework: Swiss Knife to Ethereum Tooling

ProtoLayers Talks · December 2024 · 20:17

Jan Kalivoda, Tech Lead at Ackee Blockchain, introduces Wake, a Python-based open-source toolkit for Solidity developers. Practical examples show how the framework streamlines unit testing, fuzzing and vulnerability scanning, so that Ethereum teams can catch bugs in smart contracts earlier in their development process.

Speakers

Topics

From ProtoLayers Talks, hosted by ProtoLayers.

Transcript

okay so uh welcome to my talk um uh today I want to introduce you Vue framework uh which uh is framework for solidity development uh and testing and so on and it could potentially enhance here our tooling stack my name isan uh and I am Tech lead at a blockchain we are doing uh mostly blockchain security audits but also apart from that uh we are developing open source tools where wake is one example of that uh also we are onboarding some new developers to blockchain where uh we are doing for example some online courses but we are also teaching on Czech

Technical University at bar okay uh we are currently I think three years more than three years in the space and we already worked with uh protocols such as one Lio and save and uh that will be the self introduction and we can right jump to the tooling part so uh I will have a question on you how much uh people here is like a testing their code no one oh that's shame okay so uh I hope that there will there will be at least

some one then and who is fuzzing his code so uh it's like a less popular than testing but more powerful potentially and uh another one obscure activity is static analysis uh so um uh today I will present you like a tool which combines all these things together and uh it's called W so the first part is the static analysis framework which consists of uh vulnerability detectors and for printers uh the second part is the testing part where I have to say at first that uh V is uh python solidity testing framework so everything there is

within python so we have for example available python debugger and uh you can obviously write unit and integration tests in it but also it has its own uh fuzzing engine so you can uh fuz with that and it also supports cross chain testing Fork testing and a lot of other things I think there's already covered like all the features what you need uh to properly test your smart contracts and the last important thing is it has also its own language server which uh enables us uh to uh build vs code extension on top of it okay so we will start with the static

analysis part uh where we have CLI but also the graphical interface for the detectors and printers which is provided by the BS code but you can also use for example detectors in your GitHub pipelines uh where uh it is very convenient because uh developers just push their go to the repository and it gets automatically checked against vulnerabilities uh and also there is a API to write your custom detectors which can be pretty handy because you can create some detectors which will be just a Project Specific and you don't need to have them generalized for all the projects okay so this is example of some

trigger detection uh where this specific problem lies in that that uh using for directive uh is unused in the contract which means uh like when we implemented this detector uh it turns out it is very very popular because uh that's uh just specifi uh safs using for directive at the top of the contract but then forgets to actually use it and uh it can make a confusion uh that uh those transfers in the contract are sa but they are actually not so um this is triggered when uh the directive is

unused uh so it is more like a for gold quality uh because this is like a redundant but it can can also lead to some more serious issues uh another like a uh interesting example is uh the ERC 4337 detector uh which is for Eon obstruction projects uh where it can detect uh if you use some forbidden op codes or uh you are using restricted storage access then uh you will when this detector is triggered uh then uh your project for account abstraction will not work correctly so this is like uh very convenient to use because

checking it manually uh can be uh like U more exhausted so uh actually why we decided to write our own static analysis framework was that we want to have pris detectors and uh because uh uh death are then more motivated to use the static analysis when there is not so much false positives uh so this is just an example of one chosen detector where we took 50 random contracts and uh uh try to compare it with the same detector from slitter and we got like a pretty cool F1 score which basically means uh how much you are

satisfied with the detection uh this is example how such a detector can look like uh it can be uh like hundreds lines of code but it can be also something like seven eight uh where this specific detector uh on these few lines uh is doing the thing that uh it will detect all the functions in your code that contains unsafe string and they don't have only owner modifier so if you have for example in your project you are using heavily some functions uh that uh very are using that they are unsafe you want to be sure that you will

Al always include the only on modifier then you can just write this detector for a few lines and it will check it for you then we have their printers which are very similar to detectors uh but they are about extracting some useful data from the codebase where it can be for example translated to graphs uh or it can show for example storage layout or some statistics of the code uh it has also language server integration so you can use it uh very nicely in your vs code I will show it later and it is also API for uh development of custom printers uh

which is also pretty handy this is example of uh one of the printers which uh prints the storage layout of some specific contract contct uh where if you are using upgradable contracts and doing some upgrades uh to new versions then uh it can be pretty ended to use this one because you will see if there are no storage clashes uh very easily and this is example how the printer can look like so it is very similar uh how to WR detectors how to WR printers almost the same uh but it's more about the intention you detect you want to detect some issues and with printers you want to just uh get

something useful from the code you can write printer for some onetime job uh just to print some information what you what you need but you can create also something like more generalized which you will be using like every day uh this one is like my favorite one where you print all public and external functions uh in the contract but also in the wall inheritance chain so uh I will show you later how this is like uh useful okay so let's move to the testing part uh so this is example of um uh simple test written in Wake where we

have a function which tests uh some erc20 token and uh essentially what we are doing is that we uh do just a transfer of usdt uh so it is very compact uh and uh in this special case we are doing Fork testing which can be seen in the chain. connect decorator about the uh function declaration and uh where we are connecting to some RPC endpoint which is uh on Local Host and uh with this we just get the usdt from the main net and use it for a transfer so uh this is very

useful if your protocol interacts somehow with some tokens then usdt is uh pretty unusual token uh in terms of uh API uh interface and uh you can check uh if you have everything implemented correctly and it will also work for usdt if you would like to turn this test into cross chain you will just add more chain. connect decorators so you can have for example Two Chains which are uh just uh deployed locally from scratch and you can have then for example arbit room that that is forked okay so when something EVS wrong in the test then uh it is pretty handy

to use uh call traces so uh you won't see only uh the revert message error but you will see also the Vol cold trace of the execution of the transaction and uh there you can like can more easily identify uh what you implemented wrong if it is the problem is in your test file or if it is uh in the solidity part and what is even more better is that you can use uh debugger and uh in that case when your test case fails uh then debugger is attached to it you can for example get de cult TR but you can also explore uh this the state of the chain uh get all the for example

balance state variables of some important contracts and so on so then we are getting to fast testing where we are doing something what we call like manually guided fast testing it is approach which is very similar to Foundry and different from how it is doing Aid now and uh we are doing it a way that we are specifying invariant and flows uh where flows are basically some scenarios uh what you want to do with your protocol it can be for example uh we will have a flow for a transfer then that flow will take random address a uh random amount X random address B and it

will to transfer from A to B with the amount of x uh so this will be some scenario for the protocol and uh uh this will be executed like a multiple times and we want to check if the transfer happened correctly and this can be done with a stateless or stateful invariance where stateless invariance are basically just assertions uh as we've seen uh in the test file uh these asserts uh these are basically uh the stateless invariant uh where we check just for the operation but we we are not bringing that context to another flows but we can do a state F variance which uh is

shown uh on the code example where we can track the balances of the account and uh uh check uh check uh the invariant after each flow uh if it holds uh when we are doing something like that then we are very close to something which is called differential fast testing where we are creating a model of the protocol in Python so we have uh deployed some solidity contracts with which we are interacting but we have also uh the Vol mod model in Python where it is especially useful for uh some D5 protocols such as W IO where

we had a specific formula uh from white paper which we implemented in Python and uh uh which is the W code snippet of that M equation and uh and with that we could like a around several flows over the protocol and check if the formula is always correct with uh like very big precision and this helps us uh to discover like a very like a special issues which couldn't be found with a manual review so when you have some M heavy project then you can uh discover with this some rounding rounding issues and things like that so uh this one is very handy

okay so now few uh moments of Fame so it w it was already useful for us there are some real issues what we discovered with the framework where uh the the first three rows uh are from static analysis uh and the uh then the rest is with the fuzzing uh the issues follow with static analysis are all like all various satisfying because on the day one of audit you actually get some really nice issue which you can share with the client so it's always nice it's uh something what you like a program uh will do a job for

you and then uh uh we had one guy on University which spent some time viw writing tests of unisa V fre core from hardhead to other python Frameworks and he did some measurement if you will be more interested in it uh then I can recommend to check the link in the bottom of the slide on GitHub how it was measured but uh V went from that like a uh with a pretty good performance in comparison with others so and this is just uh a high level uh slide uh which Compares like the uh current Frameworks which are like

mostly used and here I just have to say that I already for example seen projects where they were written in hardhead they were using unit test in hardhead uh they were using slitter for static analysis and they were using founder for fuzzing so instead of free Frameworks you you could for example use just one so uh it's also the reason why we are building this and yeah so this was uh the Wake the CI tool you can don't with python package manager and use it independently on this and this vs code extension is also completely independent but when you are using the both things together it's

more fun so uh the extension in vs provides you like a graphical interface for the detectors so uh it is like a more convenient uh you have vulnerability highlighting directly in the code so when you are developing some new new code uh you can actually see in the real time that you are creating some critical so it can be pretty exciting and uh this is the printer what we mentioned about printing the uh public and external functions so this is like uh it seems very trivial but it is very nice thing uh when you are just looking at some contract and the

contract can have for example 12 contracts in The Inheritance chain and these contracts can have some uh public and external functions but uh when when you are as a developer writing uh uh de contract with the Vol inheritance chain that is somewhere hidden in uh node modules and other external folders uh you you just can miss that there are some functions that are available and with this printer you just click at the bottom and you can see that in the ownable do Soul there is one function that can be called but it's not visible in the contract so uh but you will see it easily here so these printers alongside the extension uh are doing

like the code navigation uh extremely uh smooth and it can help you discover like a very easy uh box also when you're are a fan of test coverage uh then it can display uh D test coverage directly in vcode also live and the latest thing what we addit is remix like experience do Know Remix yeah I think it's pretty popular I also like it and my dream was to bring it to vs code so uh so finally uh it was it's like I think two months from release uh we get to it and uh now we

can just open any uh Pro don't any project from uh GitHub open it in your vs code and interact with it and it will be a remix so uh for example here I am choosing uh from the code base to deploy erc20 token uh where I will just uh fill uh the string and symbol and deploy it where in the transaction viewer I will see if it was successfully deployed I can check the transaction received and then I can interact with it so I can increase some elant uh I can uh transfer it and so on and and all these things uh without uh like uh writing any code just by clicking so uh it's very

nice and yeah so this was uh the extension uh we talk about vake the extension on top of the B and last thing what I have uh what I want to disclose here in Thailand that we are currently working on rewriting thee part of the framework to rest so it will be also blazingly fast soon uh so so we currently measured uh something like approximately 10 XP up but on some task it is even greater so uh I I know that python is unpopular language for someone because rust is trending now more so we were it was inevitable for us to also implement it to get rid of the Python which is slower in some things and uh

implemented by rest so if you will be also interested uh in some uh uh learning then for the test I can recommend AB some B test repository and for uh detectors to check some existing one uh and that's it that's the talk so thank you [Applause]