# Proof

The Merkle proof of an account and of some of its storage slots, as `eth_getProof` returns it
(EIP-1186).

```ts
import { Effect } from "effect";
import { Address } from "@ethect/core";
import { Eth } from "@ethect/core/rpc";

const slot0 = "0x0000000000000000000000000000000000000000000000000000000000000000";

const ADDRESS = Address.makeUnsafe("0x5FbDB2315678afecb367f032d93F642f64180aa3");

const proven = Effect.gen(function* () {
  const proof = yield* Eth.getProof(ADDRESS, [slot0], "latest");
  // proof: Proof.Proof
  return proof.storageProof.map(({ key, value }) => ({ key, value }));
});
// [{ key: "0x0000…0000", value: 7n }]
```

## Schemas

| Schema | Type | Describes | Returned by |
| --- | --- | --- | --- |
| `Proof.schema` | `Proof.Proof` | the proof of an account, with one storage proof per slot asked | [`Eth.getProof`](https://ethect.dev/rpc/eth/get-proof/) |
| `Proof.storageSchema` | `Proof.Storage` | the proof of one storage slot | `storageProof` of a `Proof.Proof` |

## Fields

`Proof.Proof`: the account, and what proves it.

| Field | Type | Notes |
| --- | --- | --- |
| `address` | `Address` | the account that was asked |
| `balance` | `bigint` | in wei |
| `nonce` | `number` | |
| `codeHash` | `Hash` (optional) | the hash of the account's code. Scroll does not send it. |
| `storageHash` | `Hash` | the root of the account's storage trie |
| `accountProof` | `ReadonlyArray<Hex>` | the encoded trie nodes from the state root down to the account |
| `storageProof` | `ReadonlyArray<Proof.Storage>` | one entry per slot asked, in the order asked |

## Storage proof fields

`Proof.Storage`: one slot, and what proves it.

| Field | Type | Notes |
| --- | --- | --- |
| `key` | `Hex` | the slot |
| `value` | `bigint` | the value of the slot, `0n` when it was never written |
| `proof` | `ReadonlyArray<Hex>` | the encoded trie nodes from the storage root down to the slot |

## Behavior

- **A value is a `bigint` here.** [`Eth.getStorageAt`](https://ethect.dev/rpc/eth/get-storage-at/) returns
  the same slot as a 32-byte `Hex` word. A proof carries it as a quantity.
- **An absent account is proven too.** Its `balance` is `0n` and its `nonce` is `0`. The nodes
  of `accountProof` then show that no account exists at that address.
- **`codeHash` can be absent.** Scroll names two hashes of its own, `keccakCodeHash` and
  `poseidonCodeHash`, and sends no `codeHash`: the proof decodes without the key.
- **`storageHash` is `storageRoot` elsewhere.** The same value is named `storageRoot` in an
  [`Account`](https://ethect.dev/rpc/types/account/).
- **Not verified.** The proof is what the node sent. Nothing in ethect checks it against a
  state root yet.
