• Stars
    star
    141
  • Rank 259,971 (Top 6 %)
  • Language
    Solidity
  • License
    GNU General Publi...
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Trustlessly prove a past storage value in a contract to other contracts

EVM Storage Proofs

Build Status npm

aka the Ethereum Storage Time Machine 🧙‍♂️

EVM Storage Proofs allow to trustlessly prove a past storage value in a contract to other contracts.

Packages

Use cases

  • Fetching a value at a past block number (i.e. ANT balance of 0xcafe1a77e... at block 5,000,000)
  • Inspecting storage values that are not exposed through a contract's public API.
  • Executing code in an EVM (or a different VM) on the EVM with real storage values.
  • More fun things 🎉

Supported clients

  • Geth >= 1.8.18 (you can start geth on a Docker container by running npm run start:geth in the evm package)
  • Parity very soon. Pull request was merged but it is still unreleased.

Installing

git clone https://github.com/aragon/evm-storage-proofs.git
npm install
cd packages/evm
npm test

Usage

The best way to learn how the library and the contracts are used is by checking the test suite for @aragon/evm-storage-proofs

Proof generation

The current implementation uses the eth_getProof RPC method (EIP 1186) to generate proofs.

For generating proofs using the JS library:

const Web3Proofs = require('@aragon/web3-proofs')

const web3proofs = new Web3Proofs(web3.currentProvider) // Or a web3.js 1.0 compatible provider

const proof = await web3proofs.getProof(contractAddress, [slot1, slot2], blockNumber)

If running on a live network, proof generation requires an archive node (unless the proof is being generated for the latest block). Whether proofs can be generated using the Ethereum light client protocol (LES GetProofs) is currently being researched.

On-chain proof verification

The StorageOracle contract can be used to verify a storage proof. There are two phases for proof verification:

1. Account proof verification

A block header contains the merkle root for the Ethereum state trie for that block. An account proof is a merkle proof of the state of an account, which verifies the fields of an account ([nonce, balance, storageHash, codeHash]) for that block height.

In order to perform this verification for an account, the StorageOracle must be provided with the block header blob, the block number and the merkle proof for the account.

The StorageOracle will verify that the hash of provided blockHeaderRLP is the valid blockhash of the block number. The stateRoot is then extracted from the block header and then the accountStateProof is verified using the stateRoot as its root.

If the proof is successfully verified, the storageHash for the account at that blockNumber is cached in the StorageOracle. The storageHash is the root of the storage merkle trie for the account.

storageOracle.processStorageRoot(account, blockNumber, blockHeaderRLP, accountStateProof)

🚨 Before the Constantinople hard fork, this phase of the proof can only be done for block numbers no older than 256 blocks. After 256 blocks, block hashes become unavailable to contracts, and the proof cannot be processed. After the Constantinople hard fork, some older block hashes will also be available under certain conditions. After the proof is processed in the contract, it can be used forever.

2. Storage proofs

A storage proof is a proof for a storage slot's value in an account at a certain block height. Contracts can store data in any of the 2^256 storage slots available, but normally they are ordered (see Solidity reference or Jorge Izquierdo's Devcon3 talk)

After having the storageHash verified and cached in the StorageOracle, merkle proofs in the account's storage trie can be verified. The storageOracle#getStorage function will verify the merkle proof and return the storage value. In case of an exclusion proof (proving that no value is stored in that slot), the function will return uint256(0).

uint256 value = storageOracle.getStorage(account, blockNumber, slot, storageProof)

Each storage slot contains a 32 byte value (uint256 or bytes32), for more complex data structures multiple storage proofs can be done and the data structure can be composed.

Even though the first step of the verification can only be done for recent blocks, once processed, storage proofs can be done at any time.

Adapters: snapshotted token balances

The StorageOracle contract just implements the logic for trustlessly getting a past storage value on other contracts, but in order to get more interesting data, adapters can be built that use the StorageOracle for proving storage and give it extra meaning.

An example adapter has been built to prove historic token balances, TokenStorageProofs, of tokens with two different internal data structures: a vanilla ERC20 token and a MiniMeToken.

The TokenStorageProofs contract exposes two functions getBalance and getTotalSupply, which provided with the correct proof, will return the historic values from the token contract storage.

⚠️ The source code of the token contract must be inspected to calculate the base storage slot for the balances mapping and the storage slot for the total supply.

🚨 The token adapter can only read raw storage values. If a token executes arbitrary logic for returning balances or the supply, a custom adapter must be built. See for example how MiniMe token balances are proven, which requires two merkle proofs because of how MiniMe stores data.

Warnings

🚨 Everything in this repo is highly experimental software.

It is not secure to use any of this code in production (mainnet) until proper security audits have been conducted.

📉 Test coverage is low

There are a lot of edge cases that haven't been properly tested yet. Test contributions would be highly appreciated!

🗃 Archive node required

Generating proofs for past block heights requires having access to an archive node.

Credits and resources

More Repositories

1

client

(Aragon 1) Create and manage decentralized organizations on Ethereum.
JavaScript
825
star
2

use-wallet

👛 useWallet() · All-in-one solution to connect a dapp to an Ethereum provider.
TypeScript
738
star
3

aragonOS

(Aragon 1) Reference implementation for aragonOS: a Solidity framework for building complex dApps and protocols
Solidity
650
star
4

aragon-apps

(Aragon 1) Aragon apps developed by Aragon Core Devs (smart contracts + webapps)
JavaScript
386
star
5

ui

🦚 UI kit for decentralized apps
JavaScript
342
star
6

govern

🦅 Optimistic DAOs
TypeScript
154
star
7

dao-templates

(Aragon 1) Monorepo for all Aragon made organization templates
JavaScript
154
star
8

connect

(Aragon 1) Seamlessly integrate DAO functionality into web and node.js apps.
TypeScript
144
star
9

nest

A grants program to support the development of the ecosystem
140
star
10

radspec

🤘 Radspec is a safe interpreter for Ethereum's NatSpec
JavaScript
139
star
11

aragon-network-token

Smart contracts for the Aragon Network Token
Solidity
116
star
12

aragon-court

🧿 A subjective oracle secured by cryptoeconomics
JavaScript
113
star
13

whitepaper

An opt-in digital jurisdiction for DAOs and sovereign individuals
112
star
14

aragon-cli

CLI for creating and publishing Aragon apps
JavaScript
90
star
15

osx

Aragon OSx Protocol
TypeScript
85
star
16

aragon.js

(Aragon 1) A monorepo of JavaScript libraries for interacting with Aragon
JavaScript
83
star
17

aragon-wiki

The Aragon wiki
HTML
76
star
18

AGPs

Aragon Goverance Proposals repository
Standard ML
60
star
19

deployments

Real-world deployments of code powering Aragon organizations to Ethereum networks
Solidity
54
star
20

governance

Proposals about governance models for the Aragon project and the Aragon Network
52
star
21

aragon-monthly

Aragon Monthly is a community curated monthly digital newspaper about DAOs and the Aragon ecosystem
50
star
22

flock

The grants program for the Aragon project teams
45
star
23

app

Human-centered DAO infrastructure
TypeScript
45
star
24

aragon-react-boilerplate

(Aragon 1) React boilerplate for Aragon applications
JavaScript
43
star
25

court-dashboard

Aragon Court dashboard
JavaScript
39
star
26

aragon-desktop

(Aragon 1) Managing an decentralized organization on a desktop near you
JavaScript
37
star
27

labs

Used for organization and collaboration on research and development initiatives under the Aragon Labs umbrella.
33
star
28

hack

(Aragon 1) Content and source code for the Aragon Developer Portal
JavaScript
31
star
29

design

UI/UX designs for the Aragon client and associated apps
30
star
30

staking

Staking app
Solidity
30
star
31

aragon-id

Aragon's simple identity solution to allow easy and secure ENS name assignments
Solidity
27
star
32

KeybaseRegistry

On-chain registry of Ethereum addreses <> https://keybase.io identities
JavaScript
27
star
33

sdk

Aragon JS SDK
TypeScript
25
star
34

buidler-aragon

(Aragon 1) Buidler plugin for Aragon App development
Solidity
24
star
35

aragon-chain

(Deprecated) Proof-of-Stake, EVM-compatible blockchain focused on DAOs
Go
24
star
36

your-first-aragon-app

(Aragon 1) Template to help you build your first Aragon application
JavaScript
21
star
37

token-amount

💸 TokenAmount · A transportable object for token amounts with formatting.
TypeScript
20
star
38

aragen

(Aragon 1) Generate an Aragon environment
JavaScript
20
star
39

aragon-chain-spec

Reference specification for Aragon Chain
18
star
40

use-token

💰 useToken() · No fuss Ethereum token metadata.
JavaScript
18
star
41

aragon-react-kit-boilerplate

React boilerplate for Aragon applications
JavaScript
17
star
42

apm.js

JavaScript library for the Aragon Package Manager
JavaScript
16
star
43

aragon-example-application

A simple example module for Aragon
JavaScript
15
star
44

convert.aragon.org

Convert between your Aragon tokens
JavaScript
14
star
45

protocol

Aragon Protocol
JavaScript
14
star
46

use-inside

🔬useInside() · Deep tree inspection for your React components.
TypeScript
14
star
47

plumbery

A collection of experiments and research artifacts for Aragon Connect.
TypeScript
13
star
48

aragon.org

Aragon's website
JavaScript
13
star
49

court-subgraph

Aragon Court subgraph
TypeScript
13
star
50

network

The source code, implementation spec, and Agreement of the Aragon Network.
13
star
51

liquidity.aragon.org

liquidity.aragon.org
TypeScript
12
star
52

use-viewport

🌅 useViewport() · Viewport sizes and helper functions for responsive applications, quick and easy.
TypeScript
12
star
53

contract-helpers

Helpers for Aragon smart contract development
JavaScript
11
star
54

multichain-voting

Solidity
10
star
55

minime

Minime Token
Solidity
10
star
56

protocol-dashboard

Aragon Protocol Dashboard
JavaScript
10
star
57

anj.aragon.org

Aragon Court jurors onboarding microsite
JavaScript
10
star
58

apm-serve

Web 2.0 server for Web 3.0 APM hosted dApps
JavaScript
9
star
59

ods

Implementation of the Aragon's Open Design System
TypeScript
8
star
60

solidity-inspector

Extract actionable metadata from Solidity source code
JavaScript
8
star
61

network-dashboard

Aragon Network Cash DAO Dashboard
JavaScript
8
star
62

aragon-app-dx

This project is meant to discuss and shape the ideal experience we want for Aragon app developers (based on the Aragon React Kit Boilerplate).
JavaScript
8
star
63

simple-storage-example-plugin

Starter of an Aragon OSx Plugin project developed with Solidity and HardHat
TypeScript
7
star
64

aragon-network-deploy

Aragon Network deployment scripts and outputs
JavaScript
7
star
65

protocol-backend

Aragon Protocol Backend
JavaScript
7
star
66

court-precedence-campaign

Dispute contents for Aragon Court's precedence campaign
Solidity
6
star
67

erc3k-legacy

Reference executable spec of ERC-3000, the standard for binding off-chain voting
6
star
68

apm-contracts

Deprecated repo, please see aragonOS
6
star
69

prototypes

Concepts / prototypes / experiments
JavaScript
6
star
70

osx-cli

deploy and manage osx plugins with ease
TypeScript
6
star
71

aragondac-community

5
star
72

aracon-website

Website for Aracon - The Aragon Conference
JavaScript
5
star
73

blog.aragon.org

Ghost theme for the Aragon Project blog
HTML
5
star
74

aragonette

An Aragon OSx simplified UI template for your custom DAO
TypeScript
5
star
75

strategy-governance-hyperstructure

A strategy document explaining how Aragon could become a governance hyperstructure.
5
star
76

aragon-bare-boilerplate

Bare boilerplate for Aragon applications
JavaScript
5
star
77

concierge

Aragon Concierge Kits
JavaScript
5
star
78

forum.aragon.org

Aragon Forum's theme
SCSS
5
star
79

ppf

JavaScript
4
star
80

osx-plugin-template-hardhat

TypeScript
4
star
81

svrp

Simple Voting Relay Protocol
JavaScript
4
star
82

signaling

Aragon Signaling App
JavaScript
4
star
83

issues

A centralized repo for managing public issues with the Aragon desktop app, the web app and the contracts that power them. Purely technical topics belong to each project repository.
4
star
84

console

(Aragon 1) The place to fine-tune all parts of your organization.
TypeScript
4
star
85

faucet

JavaScript
4
star
86

github

Github practices and code standards
4
star
87

slack-bot

Slack bot that monitors public channels to help users
PHP
4
star
88

specs

A collection of specs describing how Aragon works
4
star
89

network-dao-charter

This repository versions the Aragon Network DAO Charter document.
TeX
4
star
90

geo-browser-contracts

Smart contracts powering the GeoBrowser foundation
TypeScript
3
star
91

dao-subgraph

Aragon organization subgraph
TypeScript
3
star
92

agp-sign

Script to automate the Aragon Association board approval or rejection of AGPs
JavaScript
3
star
93

convert-recover.aragon.org

Mini recovery page for Buy and Sell Orders for ANT/ANJ on the bonding curve.
JavaScript
3
star
94

intertron

IPC for Electron
JavaScript
3
star
95

help

Documentation and files related to help.aragon.org
HTML
3
star
96

research-blog

HTML
3
star
97

security-review

In-flight requests for Aragon Network components that require external security review
3
star
98

optimistic-token-voting-plugin

Optimistic governance plugin for OSx
Solidity
3
star
99

community

Organizing Aragon community efforts in an accessible, collaborative format
3
star
100

osx-plugin-template-foundry

Solidity
3
star