# Cheatcalls EIP by Kris Kaczor | Devcon SEA

- Speakers: [Kris Kaczor](https://streameth.org/speakers/kris-kaczor)
- Channel: [Devcon](https://streameth.org/devcon)
- Date: 2025-10-09
- Duration: 24:20
- Topics: Science & Technology
- Watch: https://streameth.org/watch/yt-uG5SEBzh3qg
- YouTube: https://www.youtube.com/watch?v=uG5SEBzh3qg

## Description

Development nodes, such as Anvil, Hardhat, and Tenderly, provide specialized methods to manipulate blockchain state. For example, the `anvil_setCode` method allows arbitrary overriding smart contract code. 

Unfortunately, each node implements a slightly different set of methods with varying behaviours, resulting in wasted development hours and potential vendor lock-in.

In my talk, I introduce a new EIP that proposes standardized `cheat_*` methods with well-defined interfaces and behaviour.

Speaker(s): Kris Kaczor
Skill level: Intermediate
Track: Developer Experience
Keywords: Developer Infrastructure, DevEx, Best Practices, hardhat

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

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 Swarm, IPFS and more.

Devcon is the Ethereum conference for developers, researchers, thinkers, and makers. 
Devcon SEA was held in Bangkok, Thailand on Nov 12 - Nov 15, 2024.
Devcon is organized and presented by the Ethereum Foundation. To find out more, please visit https://ethereum.foundation/

## Transcript

[Music] [Music] hi I'm Chris kater and this is U chito's etherum Improvement proposal and attemp to standardize uh an interface of etherum development nodes so let me Begin by painting a picture of a landscape of etherum noes so on one end we have production nodes so this is your GFF your ref your Arun stuff like this so these notes are all about strictly hopefully strictly following consensus rules of etherum uh they're about being a good citizens in the you know between different nodes so you know mining blogs verifying blocks uh gossiping blocks in the PE peer-to-peer Network stuff like this uh and they are totally not about like you know giving developers any control over the state because they need to strictly follow consensus rules um on the other hand uh on the other end we have test environments these are not really full nodes they're more like focused only on executing uh evm codee but they so this is Foundry this is hard hat and these Solutions are all about giving control to the developers so um here uh while you develop your smart contract you can easily I don't know deal erc20 tokens or ethereum uh or or ethereum native currency you can warp time uh you can uh you can do things like this uh and this is very useful to put a uh the uh put your smart contract in a desired state so so you know you can test complex uh scenarios and somewhere in the middle we have the development noes so um these are tools like Anvil part of Foundry like hard Hut node like tenderly or build bear so these uh development nodes are um on one hand they are like proper almost proper etherum noes so you know you can ask them about blocks about logs and so on and so forth like that they Implement most of the standard Json uh RPC interface but on the other hand they also give developers some uh control over their state so they have these special Json RPC methods that allow developers to control them so let's dive into these development nodes because this is this is what my presentation is focused on and turns out they are very useful so first of all they support forking so instead of creating like you know pure empty instance of a node usually you Fork it from some other node most likely a main net node maybe on a particular block um another aspect is that they can be both local or running in the cloud so uh a good example uh so basically development nodes Shine for all sorts of uh uh integration testing when you need to test both your smart contracts and your offchain system so for example in spark we simulate every governance spell um we simulated on a uh tenderly Fork running in the cloud and uh we paste a GitHub uh comment on a PR with a spell um pointing to the you know UI with this uh Network connected to so a reviewer of the spell can e easily visually inspect the the the impact of the spell on the UI um also we have like a lot of endtoend tests uh written for our front end using uh uh development nodes and also we have like complex uh systems um balancing liquidity between multiple chains and guess what we're also running like multiple uh instances of um development uh development nodes running together and acting as a like you know layer one and layer twos um and as I mentioned they development nodes give developers control U over their state with these Special Json RPC methods and let's let's talk about them so um you know basically every more complex testing scenarios uh scenario requires developers to basically uh bypass regular uh consensus rules so um one of the methods so let me present some of these special Json RPC calls so for example evm set next block timestamp allows uh developers to control the time stamp of the next not yet Mind Block you can imagine that this is pretty useful when you need to assert that I don't know some exact amount of interests were was calculated correctly then we have evm revert which enes to revert to previously created snapshot so it's like a dump of a state at particular of a state of the blockchain at a particular moment uh then we have set earc 20 token balance which does what you expected to do um or does it uh and there's unveil mine for mining new blocks uh and there are many other methods like uh really God knows how many because they are not documented properly and as you can see like some of them have different prefixes but the most important thing is that all of these methods have compatibility issues for example evm set next block timestamp on some of the implementation it will actually mine a new block right away which makes writing deterministic tests impossible evm revert in some of the implementation it allows you to revert to a snapshot only once and then the snapshot is like destroyed um 1030 set C20 token balance only exists in like uh 1030 and build bar so if you want to if you relied on this Behavior to me arbitrary C20 tokens and you want to I don't know switch to Anvil guess what you you need to write your own implementation somehow um Anvil mine uh works great but uh only some of the development nodes actually have like a proper mle and some others uh just like automatically mind transactions as they come um so all of these incompatibilities uh reduce the the speed of development and make like basically simple things hard uh and this is why I why we created cheat C itm Improvement proposal it's an up it's a standard to be implemented by all these development nodes by Anvil tenderly buildar and harad of course we're talking with the team to make it to make it happen uh but basic idea is that it's like Foundry cheat codes but for Json RPC so this is why it was uh named cheat codes uh EIP um it's all about like reducing lockin in a particular uh node implementation and increasing theability so imagine that you develop a DB and you don't devel a DB specifically for Alchemy or for uh I don't know uh infura right like you can switch rpcs without any issues guess what when you're writing like uh this testing scenarios like integration test you develop it for a particular node right now and you can think that this is not a huge problem but turns out that it is because often you want to uh switch from local instance to um instance running in the cloud because I don't know you want to have a sharable link with something for everyone everybody or you want to use a superior debugging tools that are only available in one of the environments right um and uh and the the chitos EIP is um is of course like a list of cheat calls that we want these nodes to implement but it's also a testing uh suit uh to verify the conformance to this spec um all of these cheat codes share common prefix called cheat uncore and uh just to give you a little bit of taste like they they they touch things like time management mining control snapshots impersonation balance and storage management and some other areas so now let me walk you through some of the cheat go so time management um as I already mentioned like this is very useful to be able to calculate interests deterministically and so on so we have two cheat codes here cheat increase time which um mines a new block with a particular time stamp uh with with a time time stamp increased by a particular number of seconds uh but I think more useful is cheat set next block timestamp which doesn't mine a new block but once the new block is mined it's going to have like an exact time stamp um and guess what like this is properly specified and we have proper tests to catch all these mistakes that uh happen in happened in some of the implementations uh then we have mining controls so in cheat calls we have a proper mle and uh first of all you can just mine empty blocks with cheat mine uh but I think the more interesting is cheat mining mode which enables you to set one of few um mining modes like for example the default is auto so basically as transaction come the new blocks will be mined but you can set it to manual uh to uh basically stop block production and you will be required to use cheat mine to to B to mine new blocks and all the transactions that are going to send are going to be inserted into mle uh and there's also like interval mining so something that we're used to when dealing with main net um and speaking about mle uh we can we have a control how the block production chooses transactions from the mempo it could be random it could be like you know High highest fee first or first in first out um and also we have control of uh dropping the transactions from the MEO so all of the methods allow you to test complex block submission uh systems where you can simulate rears you can simulate drop trans Dro transactions from the mle and so on and so forth um then we have bunch of cheat calls uh regarding snapshots uh so cheat snapshot creates a snapshot and then we have cheat reverse snapshot which reverts to the to to the previously created snapshot and of course we make sure that you can revert to a given snapshot multiple times um impersonation is quite important because often you want to impersonate an account that you don't hold a private key of so for example imagine that you want to push a Oracle update but obviously you won't have private key to the of the Oracle so you can impersonate an account uh of uh of an owner of the Oracle and and push uh an update and if you're familiar with the previous implementation you were able to either impersonate a single account or imp and or sometimes impersonate all of them at once so we opt in into just impersonating every account automatically um so this is what cheat impersonate all accounts does uh and you have control either of either you use impersonation or not because your client Library if you provide a private key uh they're going to automatically use if send raw transaction so you send a sign transaction to the node and if you don't have a private key uh just a uh just an address the the libraries are going to use if send transaction which contains all the uh all the information about the transaction and no uh action like Signs it or just pretends that that signs that they are signed um we also created a meta uh cheat call for um inspecting the the current state of the uh of the node so by calling cheat info you get bunch of this basic information about the state of different cheat cods like know what's the mining mode what's the uh what's the state of imperson impersonation and so on and so forth and also it returns you a uh cheat call spec version so this is to Future proof uh this proposal when there will be probably more proposal proposals uh extending it um now let's talk about balance and Stage management because this is one of the most important things that you will likely do on development noes so cheat set balance enables us to set a balance of a native token but cheat set erc20 token balance does the same for arbitrary erc20 tokens and this is best ever implementation because rc20 token standard doesn't talk about how to mine tokens and so on uh so you cannot do it in every single case but we can actually come up with an approach that works most of the times and I'm going to talk about it in a second finally we have cheat set storage at which enables us to set a particular storage slot of a particular account so how does this uh how does setting a particular er20 token balance could work so uh with cheat set storage ad we can tweak we can set arbitary storage slot the problem is that we don't know which storage slot holds a value uh holds a balance of a particular account uh so just a reminder evm storage is like a huge UE 256 to U in 256 map scoped for each contract um and solidity storage layout says more or less that each property gets an index and if the property is a mapping then to find the storage slot you actually take an index and you take the the the value of the key uh I mean the key and you hash them and this is your storage slot so we can actually set arbitrary LGE uh arbitrary erc20 token balances by tracing the balance of uh uh balance of uh call of a for a particular account first um and then we can basically you know iterate over touched uh storage slots and change them until we find the one that holds a proper balance and this is actually how Forge uh STD um deal uh cheat call uh sheet code Works under the hood uh so this implementation is pretty good it works with most erc20 token balance token uh implementations and if you're doing something very custom you probably want to come up with your own mock for a given contract or something like this so what's the state of this uh EIP so uh it's in pre-draft State meaning that it's submitted to etherum magicians uh but uh it's uh it's not yet submitted to the EIP repository uh there are three contributors two contributors other than me so special thanks for p and Emmanuel Anthony for helping me with this proposal and all the teams of developing the nodes are already familiar with the spec and we're talking with them and even today we had a we had a pretty good discussion um you know tweaking some some of the behavior and here's a QR code for uh for the to e magicians forum and you're all invited to to contribute comand and so on and also I'm more than aware that pushing standards in the industry it's not necessary easy thing to do and you know there's this obligatory K KX CD comic strip uh saying like oh there are 14 competing standards it's ridiculous we need to create another one that is universal and guess what there are 15 competing standards now so luckily in this case we don't have any competing standards it's just something that wasn't standardized ever so I I hope we'll have a better time uh doing that but I'm also familiar I'm also aware that it can take uh some time uh for teams to implement it and there's this alternative client side approach where we can emulate and try to uh you know smoo out some rough edges on the client side so this would be best effort implementation some of the things won't work because uh there it's just impossible to do it client side but we can you know document actually uh what's possible what's not uh we can warn user uh warn users about incompatibilities and actually one of the more complex cheat codes like set your C20 token balance actually it can be implemented client side because you can get you can trace uh any call uh using uh access lists so it's possible to to implement such thing for example uh client side and we actually have internally a prototype of this approach and uh you know it's something that that that might help with transitioning for the full uh full full proposal and uh that would be it thank you guys and here's a QR code to the spec again and uh as I said you're all invited to contribute and I can't hear can't wait to hear your comments and opinion opinions thank you gra great job thank great presentation thanks so much so with that remember you can scan the QR code you can submit your questions yeah I see some some hearts somebody's loving the questions and the presentation and you can also vote for the the questions that you like the most so let's start with the top one when impersonating what does EC recover do I'm thinking about use case like permit to yes so this is something that we decided not to tackle yet this is a known problem like it also doesn't work uh right now what my um suggestion is is that if you need a signature most likely the address of the account that you need a signature of is somewhere in the AV storage of the contract so what you can do is you can overwrite the storage slot with a address with a with an address of a uh of a uh you know that that you know the the private key of so this way you just bypass this this problem and you don't use uh impersonation at all you just set St slot great uh the next one is can we have a cheek cheat mining mode where time sys do not increase automatically at all um time stamps of the blocks right uh yeah I think it might be a good idea because actually it's a it's it's a problem that uh they are picked automatically and yeah I agree this might be a good idea to just I don't know crash instead of mine a new block and then you would need to set the time stamp of a block explicitly before so yeah I definitely think it makes definitely sense so thanks for this comment and whoever did it or if you guys have other ideas please find Chris uh after this talk I think he will appreciate that what about the get storage range or even the get all storage of a contract helpful to match the State against an expected snapshot after every AC uh Test action yes this is uh this is great question because iterating over storage slots is like a particularly you know difficult problem to deal with um so you know uh this is like a first version of the of the spec and I expect there would be more and maybe this is one of the problems that that you know can be tackled in the future one of the uh like guiding principles of writing iips is to keep them focused so I explicitly uh wanted not to you know deal with too many problems at once but I think like this would be an interesting uh challenge to to tackle and some of the notes like argon have some special methods to iterate over the storage slots great but yeah scope scope crep is real a real issue on engineering okay wouldn't impersonate all hide bugs about misuse of certain private Keys yes so I don't think so in my experience like it's very it's much much useful to to to to use impersonate all than you know worrying about oh did I impersonate the particular account or not um as I said like this should be the dealt private uh client side right like if you don't want to impersonate an account you shouldn't you know have private key of this account lying somewhere in the client Library this is this is my current view on this thing I was also thinking about that maybe it's a little bit too much but you know uh talk to me I'm I'm open to any suggestions and like etherum magicians is like I guess the perfect place to to leave such comments or you can talk to me here yeah we need more more reviewers more ideas all right can we have a cheat restart note to clean up State and cheat reverse state to recover State yeah so Anvil I think has something along these lines um the problem that that I the problem why it's not currently part of the spec is that the spec is has to be like Universal and has to work with the uh R nodes running in the cloud as well as like you know running locally and this doesn't really make sense for the ones running in the cloud like I think Anvil caus it uh evm or Anvil reset so it's possible to do I'm just not sure if should it if it should be part of the standard right yeah I think that was the last one again wanted to thank you great presentation great questions and please give a round of applause thank you Chris
