Skip to content

0age/RStore

Repository files navigation

RStore

GitHub Build Status standard-readme compliant PRs Welcome

RStore - use the runtime code of metamorphic contracts for dynamic storage.

This contract uses metamorphic contracts in place of standard storage in order to save gas for certain applications. Then, extcodecopy is used to retrieve values from the runtime code of a metamorphic contract, which can be redeployed after a selfdestruct in order to update storage. This is bleeding-edge stuff, so use at your own risk!

There are actually two different metamorphic contracts that are used in alternating order to support single-transaction storage updates. Each caller also has their own, independent associated metamorphic storage contracts. Gas usage can almost certainly be optimized further from here - this is meant to serve as a proof-of-concept of using contract runtime code for storage.

DISCLAIMER: this implements a few highly experimental features - be sure to educate the users of your contract if it will rely on metamorphic contracts for storage! These contracts have not yet been fully tested or audited - proceed with caution and please share any exploits or optimizations you discover.

For additional context and an explanation of the initialization code used to deploy metamorphic storage contracts, check out this post.

Table of Contents

Install

To install locally, you'll need Node.js 10+ and Yarn (or npm). To get everything set up:

$ git clone https://github.com/0age/RStore.git
$ cd RStore
$ yarn install
$ yarn build

Usage

In a new terminal window, start the testRPC, run tests, and tear down the testRPC (you can do all of this at once via yarn all if you prefer):

$ yarn start
$ yarn test
$ yarn linter
$ yarn analyze # this takes a while and is for calculating gas usage
$ yarn stop

API

See the source code of the contracts for usage information. It's really quite simple - basically just set(bytes calldata data) and get(), plus some convenience view functions.

Maintainers

@0age

Contribute

PRs accepted gladly - make sure the tests and linters pass.

License

MIT © 2019 0age