Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Add evm_setCode and evm_setStorageAt RPC methods #649

Closed
iamdefinitelyahuman opened this issue Oct 11, 2020 · 8 comments
Closed

Add evm_setCode and evm_setStorageAt RPC methods #649

iamdefinitelyahuman opened this issue Oct 11, 2020 · 8 comments

Comments

@iamdefinitelyahuman
Copy link
Contributor

Expected Behavior

I would like to be able to insert bytecode at arbitrary addresses, and manipulate storage.

Possible Solution

I propose to add two new non-standard RPC methods:

  • evm_setCode: takes two parameters. The first is the address where the bytecode is to be added, and the 2nd is the bytecode.
  • evm_setStorageAt: takes three parameters. The first is an address, the second is an offset, the third is a 32 byte hexstring to place at that address/offset.

Context

With these methods it will be possible to recreate specific mainnet conditions so I can test against "sort-of production" without sacrificing performance (forking can be slow) or losing determinism.

It will also allow me to do things such as:

  • manipulating token balances / total supply
  • override safety parameters within a contract to simulate a potential exploit
  • simulate consequences of an off-by-one runtime compiler error
  • etc etc etc

I think there are a lot of potential use cases here.

@rymnc
Copy link
Contributor

rymnc commented Oct 15, 2020

Ah this idea is great!
I'll try working on it

@rymnc
Copy link
Contributor

rymnc commented Oct 15, 2020

I think this is related to the db_getHex, db_setHex, db_getString and db_setString rpc methods..
Ref: #180

@rymnc
Copy link
Contributor

rymnc commented Oct 15, 2020

could utilize the MPT put method

@davidmurdoch
Copy link
Member

The db methods get and set values in what is effectively a different database. These methods shouldn't have access to the chain's state trie.

@rymnc
Copy link
Contributor

rymnc commented Oct 17, 2020

Right, my bad. Still going through the codebase.
is anyone from the team working on this?

@davidmurdoch
Copy link
Member

These will likely land in the next major release or shortly thereafter.

I played around with an experimental version here: https://github.com/trufflesuite/ganache-core/blob/4a081acfad686e2f94c49f6087df6bb9722d2d1d/src/chains/ethereum/src/api.ts#L224 but literally haven't even run the code to see it fail... I accidentally included it in a commit refactoring other parts of code. 😅

That branch I linked to is a rewrite of ganache-core into TypeScript and it will be some time before it is released (and will be a significant breaking change). For the time being I'm trying to maintain the current JavaScript code base as well, so if you want, you can port the work I started over to JS, and I'll likely merge and release it.

@rymnc
Copy link
Contributor

rymnc commented Oct 17, 2020

ah okay that's cool

@MicaiahReid
Copy link
Contributor

These features are implemented by #2337.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants