ethstorageproof

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: AGPL-3.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifyEIP1186

func VerifyEIP1186(proof *StorageProof) (bool, error)

VerifyEIP1186 verifies the whole Ethereum proof obtained with eth_getProof method against a StateRoot. It verifies Account proof against StateRoot and all Storage proofs against StorageHash.

func VerifyEthAccountProof

func VerifyEthAccountProof(proof *StorageProof) (bool, error)

VerifyEthAccountProof verifies an Ethereum account proof against the StateRoot. It does not verify the storage proof(s).

func VerifyEthStorageProof

func VerifyEthStorageProof(proof *StorageResult, storageHash common.Hash) (bool, error)

VerifyEthStorageProof verifies an Ethereum storage proof against the StateRoot. It does not verify the account proof against the Ethereum StateHash.

func VerifyProof

func VerifyProof(rootHash common.Hash, key []byte, value []byte, proof [][]byte) (bool, error)

VerifyProof verifies that the path generated from key, following the nodes in proof leads to a leaf with value, where the hashes are correct up to the rootHash. WARNING: When the value is not found, `eth_getProof` will return "0x0" at the StorageProof `value` field. In order to verify the proof of non existence, you must set `value` to nil, *not* the RLP encoding of 0 or null (which would be 0x80).

Types

type MemDB

type MemDB struct {
	// contains filtered or unexported fields
}

MemDB is an ethdb.KeyValueReader implementation which is not thread safe and assumes that all keys are common.Hash.

func NewMemDB

func NewMemDB() *MemDB

NewMemDB creates a new empty MemDB

func (*MemDB) Get

func (m *MemDB) Get(key []byte) ([]byte, error)

Get returns the value of the key, or nil if it's not found

func (*MemDB) Has

func (m *MemDB) Has(key []byte) (bool, error)

Has returns true if the MemBD contains the key

func (*MemDB) Put

func (m *MemDB) Put(key []byte, value []byte)

Put sets or updates the value at key

type QuantityBytes

type QuantityBytes []byte

QuantityBytes marshals/unmarshals as a JSON string in hex with 0x prefix encoded as a QUANTITY. The empty slice marshals as "0x0".

func (QuantityBytes) MarshalText

func (q QuantityBytes) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (*QuantityBytes) UnmarshalText

func (q *QuantityBytes) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type SliceData

type SliceData [][]byte

SliceData marshals/unmarshals as a JSON vector of strings with in hex with 0x prefix.

func (SliceData) MarshalJSON

func (s SliceData) MarshalJSON() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (*SliceData) UnmarshalJSON

func (s *SliceData) UnmarshalJSON(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type StorageProof

type StorageProof struct {
	Height       *big.Int        `json:"height"`
	Address      common.Address  `json:"address"`
	Balance      *hexutil.Big    `json:"balance"`
	CodeHash     common.Hash     `json:"codeHash"`
	Nonce        hexutil.Uint64  `json:"nonce"`
	StateRoot    common.Hash     `json:"stateRoot"`
	StorageHash  common.Hash     `json:"storageHash"`
	AccountProof SliceData       `json:"accountProof"`
	StorageProof []StorageResult `json:"storageProof"`
}

StorageProof allows unmarshaling the object returned by `eth_getProof`. From https://eips.ethereum.org/EIPS/eip-1186:

Parameters

   DATA, 20 Bytes - address of the account.
   ARRAY, 32 Bytes - array of storage-keys which should be proofed and
     included. See eth_getStorageAt
   QUANTITY|TAG - integer block number, or the string "latest" or
     "earliest", see the default block parameter

Returns

Object - A account object:

balance: QUANTITY - the balance of the account. See eth_getBalance
codeHash: DATA, 32 Bytes - hash of the code of the account. For a simple
  Account without code it will return
  "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
nonce: QUANTITY, - nonce of the account. See eth_getTransactionCount
storageHash: DATA, 32 Bytes - SHA3 of the StorageRoot. All storage will
  deliver a MerkleProof starting with this rootHash.
accountProof: ARRAY - Array of rlp-serialized MerkleTree-Nodes, starting
  with the stateRoot-Node, following the path of the SHA3 (address) as
  key.

storageProof: ARRAY - Array of storage-entries as requested. Each entry
  is a object with these properties:
    key: QUANTITY - the requested storage key
    value: QUANTITY - the storage value
    proof: ARRAY - Array of rlp-serialized MerkleTree-Nodes, starting
      with the storageHash-Node, following the path of the SHA3 (key) as
      path.

NOTE: QUANTITY is supposed to follow this spec: https://infura.io/docs/ethereum#section/Value-encoding/Quantity but go-ethereum sometimes gives the string without the `0x` prefix

type StorageResult

type StorageResult struct {
	Key   QuantityBytes `json:"key"`
	Value QuantityBytes `json:"value"`
	Proof SliceData     `json:"proof"`
}

StorageResult is an object from StorageProof that contains a proof of storage.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL