webevm 0.0.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +674 -0
- package/dist/engine.d.ts +69 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +269 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/intrinsic-gas.d.ts +149 -0
- package/dist/intrinsic-gas.d.ts.map +1 -0
- package/dist/intrinsic-gas.js +94 -0
- package/dist/intrinsic-gas.js.map +1 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +1743 -0
- package/dist/node.js.map +1 -0
- package/dist/persistence.d.ts +22 -0
- package/dist/persistence.d.ts.map +1 -0
- package/dist/persistence.js +54 -0
- package/dist/persistence.js.map +1 -0
- package/dist/revm-state-store.d.ts +89 -0
- package/dist/revm-state-store.d.ts.map +1 -0
- package/dist/revm-state-store.js +394 -0
- package/dist/revm-state-store.js.map +1 -0
- package/dist/revm.d.ts +124 -0
- package/dist/revm.d.ts.map +1 -0
- package/dist/revm.js +657 -0
- package/dist/revm.js.map +1 -0
- package/dist/sender-recovery.d.ts +78 -0
- package/dist/sender-recovery.d.ts.map +1 -0
- package/dist/sender-recovery.js +53 -0
- package/dist/sender-recovery.js.map +1 -0
- package/dist/state-manager.d.ts +327 -0
- package/dist/state-manager.d.ts.map +1 -0
- package/dist/state-manager.js +439 -0
- package/dist/state-manager.js.map +1 -0
- package/dist/storage-keys.d.ts +21 -0
- package/dist/storage-keys.d.ts.map +1 -0
- package/dist/storage-keys.js +113 -0
- package/dist/storage-keys.js.map +1 -0
- package/dist/types.d.ts +680 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/worker-client.d.ts +21 -0
- package/dist/worker-client.d.ts.map +1 -0
- package/dist/worker-client.js +77 -0
- package/dist/worker-client.js.map +1 -0
- package/dist/worker-entry.d.ts +32 -0
- package/dist/worker-entry.d.ts.map +1 -0
- package/dist/worker-entry.js +29 -0
- package/dist/worker-entry.js.map +1 -0
- package/dist/worker-host.d.ts +75 -0
- package/dist/worker-host.d.ts.map +1 -0
- package/dist/worker-host.js +188 -0
- package/dist/worker-host.js.map +1 -0
- package/package.json +90 -2
- package/src/engine.ts +300 -0
- package/src/index.ts +46 -0
- package/src/intrinsic-gas.ts +191 -0
- package/src/node.ts +1959 -0
- package/src/persistence.ts +80 -0
- package/src/revm-state-store.ts +455 -0
- package/src/revm.ts +809 -0
- package/src/sender-recovery.ts +142 -0
- package/src/state-manager.ts +531 -0
- package/src/storage-keys.ts +150 -0
- package/src/types.ts +701 -0
- package/src/worker-client.ts +112 -0
- package/src/worker-entry.ts +31 -0
- package/src/worker-host.ts +232 -0
package/dist/revm.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revm.js","sourceRoot":"","sources":["../src/revm.ts"],"names":[],"mappings":"AAuDA,OAAO,EAAC,aAAa,EAAE,WAAW,EAAE,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAE7E,OAAO,EAAC,UAAU,EAAiC,MAAM,WAAW,CAAC;AAErE,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAC,uBAAuB,EAAC,MAAM,uBAAuB,CAAC;AAU9D,wEAAwE;AACxE,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAW1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,MAAM,CAAC,MAAM,qBAAqB,GACjC,MAAM,CAAC,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAA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O,CAAC;IACpD,MAAM,QAAQ,GAAG,eAAe,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAClE,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sender-recovery.ts — deriving a transaction's SENDER from its signature using a
|
|
3
|
+
* curve implementation the node is handed, rather than the one `@ethereumjs/tx`
|
|
4
|
+
* carries.
|
|
5
|
+
*
|
|
6
|
+
* WHY THIS MODULE EXISTS. `senderMode:'recover'` pays a fixed ecrecover on every
|
|
7
|
+
* transaction, and it is the single dominant cost of a small one. An engine whose
|
|
8
|
+
* module ALREADY contains secp256k1 — `webevm/revm`, whose `0x01`
|
|
9
|
+
* precompile is exactly that code — can do the curve arithmetic for nothing extra,
|
|
10
|
+
* so the seam offers an optional `Engine.ecrecover` and this module is what turns
|
|
11
|
+
* that primitive into a sender. With no such engine the node keeps calling
|
|
12
|
+
* `tx.getSenderAddress()` (see `parseTx` in ./node.ts), which is the
|
|
13
|
+
* implementation these functions must agree with, case for case, INCLUDING the
|
|
14
|
+
* cases that must FAIL.
|
|
15
|
+
*
|
|
16
|
+
* THE DIVISION OF LABOUR, which is the load-bearing part. The engine answers ONE
|
|
17
|
+
* question — "which address produced `(r, s)` over this digest with this recovery
|
|
18
|
+
* id" — and every PROTOCOL rule stays here, above the seam:
|
|
19
|
+
*
|
|
20
|
+
* 1. THE MESSAGE. `tx.getMessageToVerifySignature()` — EIP-155's nine-field
|
|
21
|
+
* preimage for a protected legacy transaction, the type-prefixed one for a
|
|
22
|
+
* typed transaction. Asked of the transaction rather than recomputed, because
|
|
23
|
+
* a second implementation of those rules is a second thing that can be wrong.
|
|
24
|
+
* 2. EIP-2 (low `s`). NOT delegable, and this is the trap the whole module is
|
|
25
|
+
* arranged around: revm's ecrecover is the `0x01` PRECOMPILE's, and the
|
|
26
|
+
* precompile NORMALISES a high-`s` signature and returns an address —
|
|
27
|
+
* correctly, since EIP-2 constrains transactions and not the precompile. A
|
|
28
|
+
* node that simply forwarded `(hash, v, r, s)` would therefore ADMIT, on the
|
|
29
|
+
* revm engine, a transaction the default engine REFUSES: silently, with a
|
|
30
|
+
* plausible receipt, and attributed to the right signer, which is what makes
|
|
31
|
+
* it easy to miss. So the rule is enforced HERE, on the same terms
|
|
32
|
+
* `@ethereumjs/tx` enforces it (`s > n/2`, from Homestead on), and the answer
|
|
33
|
+
* is identical on every engine.
|
|
34
|
+
* 3. THE RECOVERY ID. The wire carries `v`: 27/28 for a pre-EIP-155 legacy
|
|
35
|
+
* transaction, `chainId * 2 + 35/36` for a protected one, a bare y-parity for
|
|
36
|
+
* a typed one. The 0/1 recovery id is computed here (with
|
|
37
|
+
* `@ethereumjs/util`'s own `calculateSigRecovery`, the function the fallback
|
|
38
|
+
* path uses) and validated before the engine sees it, so an engine needs to
|
|
39
|
+
* know nothing about EIP-155 and a raw `v` can never reach the curve.
|
|
40
|
+
*
|
|
41
|
+
* WHAT IT REFUSES WITH. A plain `Error`, like the `@ethereumjs/tx` path it stands
|
|
42
|
+
* in for — deliberately NOT a new `RpcError` code. An unrecoverable signature is a
|
|
43
|
+
* malformed transaction, and it has always surfaced out of
|
|
44
|
+
* `eth_sendRawTransaction*` as whatever the parse/recovery step threw; giving the
|
|
45
|
+
* engine-backed path its own code would make the same bad transaction produce two
|
|
46
|
+
* different errors depending on which engine is installed, which is the one thing
|
|
47
|
+
* the seam exists to prevent. The MESSAGE differs (it says which implementation
|
|
48
|
+
* refused, which is what a bug report needs) and the shape does not.
|
|
49
|
+
*
|
|
50
|
+
* The agreement is not argued, it is measured:
|
|
51
|
+
* `test/helpers/sender-recovery.ts` runs the two implementations side by side as a
|
|
52
|
+
* primitive AND through two nodes, over a known signer for legacy, EIP-2930 and
|
|
53
|
+
* EIP-1559 transactions and over a malformed signature, a high-`s` one and a wrong
|
|
54
|
+
* recovery id.
|
|
55
|
+
*/
|
|
56
|
+
import type { Common } from '@ethereumjs/common';
|
|
57
|
+
import { type TypedTransaction } from '@ethereumjs/tx';
|
|
58
|
+
import { Address } from '@ethereumjs/util';
|
|
59
|
+
import type { Engine } from './types.js';
|
|
60
|
+
/** The seam's curve primitive, as this module consumes it. */
|
|
61
|
+
export type EngineEcrecover = NonNullable<Engine['ecrecover']>;
|
|
62
|
+
/**
|
|
63
|
+
* WHO SIGNED `tx`, using `ecrecover` for the curve step and enforcing every
|
|
64
|
+
* protocol rule around it here.
|
|
65
|
+
*
|
|
66
|
+
* Throws when the signature authenticates nobody — a missing signature, an `s` in
|
|
67
|
+
* the upper half of the curve order (EIP-2), a `v` that is not a recovery id, or a
|
|
68
|
+
* point that does not recover. NEVER returns a "best effort" address: attributing
|
|
69
|
+
* a transaction to the wrong account is worse than rejecting it, because it
|
|
70
|
+
* charges that account, advances its nonce and produces a receipt that looks
|
|
71
|
+
* entirely right.
|
|
72
|
+
*
|
|
73
|
+
* @param tx the parsed transaction, frozen, exactly as the node holds it.
|
|
74
|
+
* @param common the node's chain parameters (chain id + hardfork).
|
|
75
|
+
* @param ecrecover the engine's curve primitive (see {@link Engine.ecrecover}).
|
|
76
|
+
*/
|
|
77
|
+
export declare function recoverSender(tx: TypedTransaction, common: Common, ecrecover: EngineEcrecover): Address;
|
|
78
|
+
//# sourceMappingURL=sender-recovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sender-recovery.d.ts","sourceRoot":"","sources":["../src/sender-recovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAa,KAAK,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACN,OAAO,EAKP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,YAAY,CAAC;AAEvC,8DAA8D;AAC9D,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;AAE/D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC5B,EAAE,EAAE,gBAAgB,EACpB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,eAAe,GACxB,OAAO,CAqDT"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Capability } from '@ethereumjs/tx';
|
|
2
|
+
import { Address, SECP256K1_ORDER_DIV_2, calculateSigRecovery, setLengthLeft, bigIntToBytes, } from '@ethereumjs/util';
|
|
3
|
+
/**
|
|
4
|
+
* WHO SIGNED `tx`, using `ecrecover` for the curve step and enforcing every
|
|
5
|
+
* protocol rule around it here.
|
|
6
|
+
*
|
|
7
|
+
* Throws when the signature authenticates nobody — a missing signature, an `s` in
|
|
8
|
+
* the upper half of the curve order (EIP-2), a `v` that is not a recovery id, or a
|
|
9
|
+
* point that does not recover. NEVER returns a "best effort" address: attributing
|
|
10
|
+
* a transaction to the wrong account is worse than rejecting it, because it
|
|
11
|
+
* charges that account, advances its nonce and produces a receipt that looks
|
|
12
|
+
* entirely right.
|
|
13
|
+
*
|
|
14
|
+
* @param tx the parsed transaction, frozen, exactly as the node holds it.
|
|
15
|
+
* @param common the node's chain parameters (chain id + hardfork).
|
|
16
|
+
* @param ecrecover the engine's curve primitive (see {@link Engine.ecrecover}).
|
|
17
|
+
*/
|
|
18
|
+
export function recoverSender(tx, common, ecrecover) {
|
|
19
|
+
const { v, r, s } = tx;
|
|
20
|
+
if (v === undefined || r === undefined || s === undefined) {
|
|
21
|
+
throw new Error('webevm: cannot recover the sender of an UNSIGNED transaction ' +
|
|
22
|
+
'(no v/r/s on the wire). Sign it client-side and resubmit.');
|
|
23
|
+
}
|
|
24
|
+
// EIP-2, on the same terms `@ethereumjs/tx` states them: from Homestead on, an
|
|
25
|
+
// `s` above n/2 is INVALID even though the curve recovers it perfectly well
|
|
26
|
+
// (it is the malleable twin of a valid signature, and it recovers to the same
|
|
27
|
+
// signer). The engine's ecrecover will not say so — the `0x01` precompile
|
|
28
|
+
// normalises it — so this is the check that keeps the two implementations
|
|
29
|
+
// answering the same thing.
|
|
30
|
+
if (common.gteHardfork('homestead') && s > SECP256K1_ORDER_DIV_2) {
|
|
31
|
+
throw new Error('webevm: Invalid Signature: s-values greater than secp256k1n/2 ' +
|
|
32
|
+
'are considered invalid (EIP-2). The transaction is REFUSED rather than ' +
|
|
33
|
+
'attributed to the address its malleable twin would recover to.');
|
|
34
|
+
}
|
|
35
|
+
// The wire's `v` -> a 0/1 recovery id. `Capability.EIP155ReplayProtection` is
|
|
36
|
+
// set only for a legacy transaction whose `v` really encodes this chain id, so
|
|
37
|
+
// this is the same branch `@ethereumjs/tx` takes; a typed transaction's `v` is
|
|
38
|
+
// already the y-parity and `calculateSigRecovery` returns it unchanged.
|
|
39
|
+
const recovery = calculateSigRecovery(v, tx.supports(Capability.EIP155ReplayProtection)
|
|
40
|
+
? common.chainId()
|
|
41
|
+
: undefined);
|
|
42
|
+
if (recovery !== 0n && recovery !== 1n) {
|
|
43
|
+
throw new Error(`webevm: Invalid Signature: v ${v} is not a recovery id on chain ` +
|
|
44
|
+
`${common.chainId()} (expected 27/28, ${common.chainId() * 2n + 35n}/${common.chainId() * 2n + 36n}, or a 0/1 y-parity).`);
|
|
45
|
+
}
|
|
46
|
+
const address = ecrecover(tx.getMessageToVerifySignature(), Number(recovery), setLengthLeft(bigIntToBytes(r), 32), setLengthLeft(bigIntToBytes(s), 32));
|
|
47
|
+
if (address === undefined || address.length !== 20) {
|
|
48
|
+
throw new Error("webevm: Invalid Signature: the engine's ecrecover recovered no " +
|
|
49
|
+
'address from this transaction, so there is nobody to attribute it to.');
|
|
50
|
+
}
|
|
51
|
+
return new Address(address);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=sender-recovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sender-recovery.js","sourceRoot":"","sources":["../src/sender-recovery.ts"],"names":[],"mappings":"AAwDA,OAAO,EAAC,UAAU,EAAwB,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACN,OAAO,EACP,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,aAAa,GACb,MAAM,kBAAkB,CAAC;AAM1B;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,aAAa,CAC5B,EAAoB,EACpB,MAAc,EACd,SAA0B;IAE1B,MAAM,EAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAC,GAAG,EAA0C,CAAC;IAC7D,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;QAC3D,MAAM,IAAI,KAAK,CACd,+DAA+D;YAC9D,2DAA2D,CAC5D,CAAC;IACH,CAAC;IAED,+EAA+E;IAC/E,4EAA4E;IAC5E,8EAA8E;IAC9E,0EAA0E;IAC1E,0EAA0E;IAC1E,4BAA4B;IAC5B,IAAI,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,qBAAqB,EAAE,CAAC;QAClE,MAAM,IAAI,KAAK,CACd,gEAAgE;YAC/D,yEAAyE;YACzE,gEAAgE,CACjE,CAAC;IACH,CAAC;IAED,8EAA8E;IAC9E,+EAA+E;IAC/E,+EAA+E;IAC/E,wEAAwE;IACxE,MAAM,QAAQ,GAAG,oBAAoB,CACpC,CAAC,EACD,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,sBAAsB,CAAC;QAC7C,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE;QAClB,CAAC,CAAC,SAAS,CACZ,CAAC;IACF,IAAI,QAAQ,KAAK,EAAE,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CACd,gCAAgC,CAAC,iCAAiC;YACjE,GAAG,MAAM,CAAC,OAAO,EAAE,qBAAqB,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,uBAAuB,CAC1H,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,SAAS,CACxB,EAAE,CAAC,2BAA2B,EAAE,EAChC,MAAM,CAAC,QAAQ,CAAC,EAChB,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EACnC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CACnC,CAAC;IACF,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CACd,iEAAiE;YAChE,uEAAuE,CACxE,CAAC;IACH,CAAC;IACD,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* state-manager.ts — the node's `stateMode:'none'` state manager.
|
|
3
|
+
*
|
|
4
|
+
* `@ethereumjs/statemanager@10.1.2`'s `SimpleStateManager` keeps storage in ONE
|
|
5
|
+
* FLAT `Map` keyed `` `${address}_${slot}` ``, and `checkpointSync()` pushes a
|
|
6
|
+
* full COPY of it. `@ethereumjs/evm` checkpoints once per MESSAGE FRAME, so every
|
|
7
|
+
* transaction pays `frames + 1` copies of ALL of state, and `clearStorage` (which
|
|
8
|
+
* the EVM calls on every contract creation) can only be a prefix scan of the whole
|
|
9
|
+
* map. Measured end to end: four ordinary transactions cost 289 ms at 100,000
|
|
10
|
+
* slots on that layout and 10 ms on this one, and one transaction at 10,000 slots
|
|
11
|
+
* already ate between a third and nine tenths of a 16.6 ms frame budget through
|
|
12
|
+
* the node's own public surface. All of it is in
|
|
13
|
+
* `docs/spikes/spike-storage-layout-cost-for-the-revm-write-half/measurements.md`.
|
|
14
|
+
*
|
|
15
|
+
* So this subclass re-layers storage. It is `Map<address, Map<slot, value>>`, and
|
|
16
|
+
* a checkpoint pushes a **storage overlay** — one checkpoint's worth of CHANGE —
|
|
17
|
+
* rather than copying anything:
|
|
18
|
+
*
|
|
19
|
+
* - `checkpointSync()` pushes an EMPTY overlay: O(1), whatever state holds.
|
|
20
|
+
* - `putStorage` writes into the TOP overlay only.
|
|
21
|
+
* - `getStorage` walks the overlay stack DOWNWARDS until it finds the slot, or an
|
|
22
|
+
* overlay that cleared the account (which hides every overlay below it).
|
|
23
|
+
* - `commit()` merges the top overlay into the one below and pops it; `revert()`
|
|
24
|
+
* just pops it, so an uncommitted write was never anywhere else to begin with.
|
|
25
|
+
* - `clearStorage(address)` is one `delete` plus one tombstone: O(that account)
|
|
26
|
+
* (no tombstone on the BOTTOM overlay, which has nothing below it to hide).
|
|
27
|
+
*
|
|
28
|
+
* ## The key is PACKED, and both sides of it import ONE encoder
|
|
29
|
+
*
|
|
30
|
+
* The keys in that `Map<address, Map<slot, value>>` are the NODE'S — the point
|
|
31
|
+
* of owning the representation — so they are packed rather than `0x`-hex: two
|
|
32
|
+
* bytes per UTF-16 code unit, 10 code units for an account and 16 for a slot.
|
|
33
|
+
* That takes a cold revm storage access from 1.31-1.33 µs to 0.36-0.39 µs —
|
|
34
|
+
* 70-73%, nearly all of it JS-side key handling — and the encoder, the
|
|
35
|
+
* measurement and the fixed-width rule are in
|
|
36
|
+
* `src/storage-keys.ts` — build a key with {@link packAddressKey} /
|
|
37
|
+
* {@link packSlotKey} and never by hand, because the synchronous revm store
|
|
38
|
+
* (`src/revm-state-store.ts`) builds its keys with the same two functions and a
|
|
39
|
+
* silent disagreement between the two would read as ZERO rather than as an error.
|
|
40
|
+
*
|
|
41
|
+
* ACCOUNTS AND CODE ARE NOT AFFECTED: those stacks are `SimpleStateManager`'s and
|
|
42
|
+
* stay keyed `address.toString()`. Neither is `dumpState`'s output, which stays
|
|
43
|
+
* `0x`-hex — {@link OverlayStorageStateManager.liveStorage} converts on the way
|
|
44
|
+
* out.
|
|
45
|
+
*
|
|
46
|
+
* ONE WORD FOR THE CONCEPT: **overlay**. The spike that produced this design
|
|
47
|
+
* called the same thing an overlay, a diff frame and a journal frame in different
|
|
48
|
+
* places; "frame" already means an EVM message frame (and, in `CONTEXT.md`, the
|
|
49
|
+
* 16.6 ms frame budget) and "journal" already means the one `@ethereumjs/evm`
|
|
50
|
+
* keeps ABOVE the state manager, so neither is free. `overlay` is, and it is
|
|
51
|
+
* defined in `CONTEXT.md`'s glossary. Use it in code, tests and commits.
|
|
52
|
+
*
|
|
53
|
+
* ## Copy-on-write is not enough, and the naive version fails SILENTLY
|
|
54
|
+
*
|
|
55
|
+
* The plausible wrong version of this is `new Map(outer)` per checkpoint: it
|
|
56
|
+
* copies the outer map and SHARES every inner map, so a child frame's write
|
|
57
|
+
* mutates the parent's map, survives a revert, and lands in committed state with
|
|
58
|
+
* no error anywhere. `test/helpers/storage-overlay.ts` keeps that version as a
|
|
59
|
+
* CONTROL and asserts it fails the same checks this class passes — a correctness
|
|
60
|
+
* claim with nothing to fail against is not a claim. (Cloning the inner map on
|
|
61
|
+
* first write fixes the leak but leaves the checkpoint O(accounts-with-storage),
|
|
62
|
+
* which is the same O(total) when state is one slot per account, i.e. exactly
|
|
63
|
+
* what per-player game state looks like. Hence overlays.)
|
|
64
|
+
*
|
|
65
|
+
* ## `storageStack` is GONE, and reading it THROWS
|
|
66
|
+
*
|
|
67
|
+
* The base class's `storageStack` is not maintained here, because it is the thing
|
|
68
|
+
* being replaced. It is deliberately made unreadable rather than left present and
|
|
69
|
+
* empty: with an empty stack still sitting there, three shipped readers answered
|
|
70
|
+
* WRONG rather than throwing (the revm store reported "this slot is zero" for a
|
|
71
|
+
* slot holding `0x2a`, `dumpState` dumped no storage at all, and the guard meant
|
|
72
|
+
* to catch a shape change passed). Wrong-but-plausible is the failure this repo's
|
|
73
|
+
* honest-edge convention exists to prevent, so any remaining reader now gets a
|
|
74
|
+
* loud error naming the replacement instead of a believable zero.
|
|
75
|
+
*
|
|
76
|
+
* ## The field-initialiser trap, which will bite the next person
|
|
77
|
+
*
|
|
78
|
+
* `SimpleStateManager`'s CONSTRUCTOR calls `this.checkpointSync()`. A subclass
|
|
79
|
+
* field declaration runs AFTER `super()` returns, so `storageOverlays = []` would
|
|
80
|
+
* overwrite whatever that first checkpoint created. There is therefore NO field
|
|
81
|
+
* declaration for it: it is created lazily inside the override.
|
|
82
|
+
*
|
|
83
|
+
* ## `clearStorage` is also an upstream-bug fix, and still is
|
|
84
|
+
*
|
|
85
|
+
* `SimpleStateManager` ships `clearStorage` as `async clearStorage() { }`: an
|
|
86
|
+
* empty body taking NO parameter, while the `StateManagerInterface` it implements
|
|
87
|
+
* declares `clearStorage(address)`. A zero-parameter method satisfies a
|
|
88
|
+
* one-parameter interface member, so TypeScript never flagged it and the address
|
|
89
|
+
* argument is silently dropped. `@ethereumjs/evm` calls it on EVERY contract
|
|
90
|
+
* creation (`evm.js:555`) precisely to guarantee a fresh contract starts with
|
|
91
|
+
* empty storage, so with the upstream no-op a contract created at an address that
|
|
92
|
+
* already holds storage INHERITS it. Reported upstream; see
|
|
93
|
+
* `docs/adr/0007-we-override-simplestatemanagers-no-op-clearstorage.md`.
|
|
94
|
+
*
|
|
95
|
+
* WHY AN OVERRIDE RATHER THAN A `pnpm patch`: a patch would fix only THIS repo's
|
|
96
|
+
* own test runs. `webevm` is a library, so a consumer resolves
|
|
97
|
+
* `@ethereumjs/statemanager` themselves and would never see our patch. The fix
|
|
98
|
+
* has to live in code we publish. That argument is even stronger for the layout,
|
|
99
|
+
* which is a representation our own `dumpState` and revm store read directly.
|
|
100
|
+
*
|
|
101
|
+
* WHAT THIS DOES NOT FIX (and cannot, in this mode): the EIP-7610 collision guard
|
|
102
|
+
* sitting just above that call rejects creation outright when the target account
|
|
103
|
+
* has non-empty storage, and it reads `account.storageRoot`. `SimpleStateManager`
|
|
104
|
+
* implements no state-root logic at all, so `storageRoot` never reflects its
|
|
105
|
+
* storage and the guard cannot fire. `stateMode:'trie'` gets the correct,
|
|
106
|
+
* spec-current behaviour from `MerkleStateManager` (creation fails with
|
|
107
|
+
* `CREATE_COLLISION`); `stateMode:'none'` clears and proceeds, which is the
|
|
108
|
+
* pre-EIP-7610 semantics and what the EVM's own call asks for. Both are far
|
|
109
|
+
* better than silently inheriting; they are not identical to each other, and that
|
|
110
|
+
* asymmetry is documented in the README's state-mode section.
|
|
111
|
+
*/
|
|
112
|
+
import { SimpleStateManager } from '@ethereumjs/statemanager';
|
|
113
|
+
import type { Address } from '@ethereumjs/util';
|
|
114
|
+
import { type HexKey, type PackedAddressKey, type PackedSlotKey } from './storage-keys.js';
|
|
115
|
+
export type { PackedAddressKey, PackedSlotKey, HexKey } from './storage-keys.js';
|
|
116
|
+
/**
|
|
117
|
+
* ONE CHECKPOINT'S WORTH OF STORAGE CHANGE: the slots written since that
|
|
118
|
+
* checkpoint, plus the accounts cleared in it.
|
|
119
|
+
*
|
|
120
|
+
* `written` holds ONLY what this overlay touched, which is what makes a
|
|
121
|
+
* checkpoint O(1): nothing is copied forward. `cleared` is the tombstone half —
|
|
122
|
+
* an account in it reads as EMPTY through this overlay, hiding every overlay
|
|
123
|
+
* below, which is what makes `clearStorage` O(that account) rather than a scan.
|
|
124
|
+
* Both are needed: without `cleared`, a clear could only be expressed by copying
|
|
125
|
+
* the account's slots forward as zeroes, which is the cost being removed.
|
|
126
|
+
*
|
|
127
|
+
* THE BOTTOM OVERLAY HOLDS NO TOMBSTONES. It is committed state, so there is
|
|
128
|
+
* nothing below it for a tombstone to hide and dropping the account's `written`
|
|
129
|
+
* entry has already cleared everything there was. Nothing ever removes an entry
|
|
130
|
+
* from a bottom `cleared` set either, so keeping them made this the one part of
|
|
131
|
+
* the layout that grew without bound — the EVM calls `clearStorage` on EVERY
|
|
132
|
+
* contract creation. Both places one could arrive are pruned at the source:
|
|
133
|
+
* {@link OverlayStorageStateManager.clearStorageAt} when no checkpoint is open,
|
|
134
|
+
* and {@link OverlayStorageStateManager.commit} when the merge target is the
|
|
135
|
+
* bottom.
|
|
136
|
+
*/
|
|
137
|
+
export interface StorageOverlay {
|
|
138
|
+
/** address key -> (slot key -> value) written IN THIS overlay, PACKED. */
|
|
139
|
+
readonly written: Map<PackedAddressKey, Map<PackedSlotKey, Uint8Array>>;
|
|
140
|
+
/** Accounts cleared in this overlay: every overlay below it is hidden for them. */
|
|
141
|
+
readonly cleared: Set<PackedAddressKey>;
|
|
142
|
+
}
|
|
143
|
+
export declare class OverlayStorageStateManager extends SimpleStateManager {
|
|
144
|
+
/**
|
|
145
|
+
* The overlay stack, bottom (committed state) to top (the innermost open
|
|
146
|
+
* checkpoint). Always non-empty: the base constructor's `checkpointSync()`
|
|
147
|
+
* seeds it.
|
|
148
|
+
*
|
|
149
|
+
* Public for the same reason `accountStack` and `codeStack` are: the revm store
|
|
150
|
+
* reads AND WRITES state SYNCHRONOUSLY and `StateManagerInterface` is async
|
|
151
|
+
* throughout (ADR 0005). Prefer {@link storageAt} / {@link liveStorage} /
|
|
152
|
+
* {@link setStorageAt} / {@link clearStorageAt} over walking this by hand.
|
|
153
|
+
*
|
|
154
|
+
* NO INITIALISER — see the header's field-initialiser trap.
|
|
155
|
+
*/
|
|
156
|
+
storageOverlays: StorageOverlay[];
|
|
157
|
+
constructor(opts?: ConstructorParameters<typeof SimpleStateManager>[0]);
|
|
158
|
+
/**
|
|
159
|
+
* Push a frame. Accounts and code exactly as upstream (they are not what this
|
|
160
|
+
* class re-layers, and copying them byte-for-byte keeps the diff honest);
|
|
161
|
+
* storage pushes an EMPTY overlay, which copies nothing at any state size.
|
|
162
|
+
*/
|
|
163
|
+
protected checkpointSync(): void;
|
|
164
|
+
/**
|
|
165
|
+
* Merge the top overlay into the one below and drop it.
|
|
166
|
+
*
|
|
167
|
+
* The clear is merged FIRST and in O(1) per account: dropping the account from
|
|
168
|
+
* the overlay below and re-tombstoning it there hides everything deeper,
|
|
169
|
+
* without touching a single slot. Then the writes land on top of that, so a
|
|
170
|
+
* clear-then-write inside one frame commits as "only the new slots".
|
|
171
|
+
*
|
|
172
|
+
* EXCEPT ON THE BOTTOM OVERLAY, WHICH KEEPS NO TOMBSTONES. A tombstone exists
|
|
173
|
+
* to hide the slots overlays BELOW it hold; the bottom overlay is committed
|
|
174
|
+
* state and has nothing below, so a tombstone there hides nothing and is never
|
|
175
|
+
* removed by anything. `@ethereumjs/evm` calls `clearStorage` on EVERY contract
|
|
176
|
+
* creation, so keeping them cost a long-lived in-browser node one permanent
|
|
177
|
+
* entry per CREATE ever executed, plus an O(addresses-ever-cleared) term in
|
|
178
|
+
* {@link liveStorage} and therefore in every `dumpState`. The `delete` is what
|
|
179
|
+
* performs the clear and it still runs, so the account still reads as cleared —
|
|
180
|
+
* {@link storageAt} falls off the end of the stack, which is the same
|
|
181
|
+
* `undefined` a tombstone would have produced. Pruned HERE, at one of the two
|
|
182
|
+
* places a bottom tombstone can be created (the other is
|
|
183
|
+
* {@link clearStorageAt}, with no checkpoint open), rather than swept later.
|
|
184
|
+
*/
|
|
185
|
+
commit(): Promise<void>;
|
|
186
|
+
/** Drop the top overlay. Everything written since the checkpoint goes with it. */
|
|
187
|
+
revert(): Promise<void>;
|
|
188
|
+
private topOverlay;
|
|
189
|
+
/**
|
|
190
|
+
* Read one slot SYNCHRONOUSLY, by key, walking the overlay stack downwards.
|
|
191
|
+
*
|
|
192
|
+
* BOTH KEYS ARE PACKED and must come from `src/storage-keys.ts`
|
|
193
|
+
* ({@link packAddressKey} / {@link packSlotKey}). A hand-built key that happens
|
|
194
|
+
* to be a string compiles and MISSES, and a miss here is indistinguishable from
|
|
195
|
+
* a slot holding zero.
|
|
196
|
+
*
|
|
197
|
+
* `undefined` means "no overlay holds this slot", i.e. zero. A zero-LENGTH
|
|
198
|
+
* `Uint8Array` is different: it means an overlay explicitly stored the empty
|
|
199
|
+
* value (the interpreter strips leading zeros before `putStorage`, so a slot
|
|
200
|
+
* zeroed by `SSTORE` is stored as empty rather than deleted) and it must stop
|
|
201
|
+
* the walk, or a cleared slot would read through to a stale value below.
|
|
202
|
+
*
|
|
203
|
+
* The stack walk is the cost this layout ADDS, and it is two map lookups per
|
|
204
|
+
* open checkpoint. Measured against frame depths 1/2/4/8 it is not
|
|
205
|
+
* distinguishable from the flat map's single lookup; see the spike.
|
|
206
|
+
*/
|
|
207
|
+
storageAt(addressKey: PackedAddressKey, slotKey: PackedSlotKey): Uint8Array | undefined;
|
|
208
|
+
/**
|
|
209
|
+
* Write one slot SYNCHRONOUSLY, by key, into the TOP overlay — the write-side
|
|
210
|
+
* twin of {@link storageAt}, and for the same reason it exists: revm's commit
|
|
211
|
+
* runs inside a synchronous wasm callback and every method on
|
|
212
|
+
* `StateManagerInterface` returns a `Promise` (ADR 0005). `putStorage` below is
|
|
213
|
+
* this function plus an `Address`.
|
|
214
|
+
*
|
|
215
|
+
* THE VALUE MUST ALREADY BE IN SHORTEST FORM, because that is what this
|
|
216
|
+
* representation holds and what `dumpState` serialises: `@ethereumjs/evm`
|
|
217
|
+
* strips leading zeros before `putStorage` (a zeroed slot arrives as a
|
|
218
|
+
* ZERO-LENGTH array, which {@link storageAt} treats as "explicitly empty" and
|
|
219
|
+
* stops the walk at). A caller handing over 32 padded bytes would write state
|
|
220
|
+
* that reads back correctly and dumps differently from the same state written
|
|
221
|
+
* by the default engine.
|
|
222
|
+
*/
|
|
223
|
+
setStorageAt(addressKey: PackedAddressKey, slotKey: PackedSlotKey, value: Uint8Array): void;
|
|
224
|
+
/**
|
|
225
|
+
* Clear one account's storage SYNCHRONOUSLY, by key — {@link clearStorage}
|
|
226
|
+
* without an `Address`, for the same synchronous-callback reason as
|
|
227
|
+
* {@link setStorageAt}. Still O(1): one `delete` plus one tombstone.
|
|
228
|
+
*
|
|
229
|
+
* NO TOMBSTONE WHEN THE TOP OVERLAY *IS* THE BOTTOM ONE, i.e. when no
|
|
230
|
+
* checkpoint is open. It is the same invariant {@link commit} keeps: a
|
|
231
|
+
* tombstone hides what overlays BELOW hold, and the bottom overlay has nothing
|
|
232
|
+
* below, so the `delete` above has already removed everything there was and the
|
|
233
|
+
* tombstone would be an entry nothing can ever remove.
|
|
234
|
+
*
|
|
235
|
+
* THIS IS THE SITE THE REVM ENGINE REACHES, and it is why the rule is here as
|
|
236
|
+
* well as in `commit()`. `runTx` checkpoints, so the DEFAULT engine's
|
|
237
|
+
* `clearStorage` on every contract creation lands three overlays deep and is
|
|
238
|
+
* pruned on the way down; `webevm/revm` commits its state changes
|
|
239
|
+
* through `src/revm-state-store.ts`'s SYNCHRONOUS callbacks with no checkpoint
|
|
240
|
+
* around them, so every CREATE on that engine clears at depth 1 and arrives
|
|
241
|
+
* straight here. Measured before this line existed: three contract creations
|
|
242
|
+
* left three permanent tombstones in the bottom overlay, one per CREATE, each
|
|
243
|
+
* of them then walked by {@link liveStorage} and therefore by every
|
|
244
|
+
* `dumpState`.
|
|
245
|
+
*/
|
|
246
|
+
clearStorageAt(addressKey: PackedAddressKey): void;
|
|
247
|
+
getStorage(address: Address, key: Uint8Array): Promise<Uint8Array>;
|
|
248
|
+
putStorage(address: Address, key: Uint8Array, value: Uint8Array): Promise<void>;
|
|
249
|
+
/**
|
|
250
|
+
* Delete every storage slot belonging to `address`. O(THAT ACCOUNT) — in fact
|
|
251
|
+
* O(1): drop this overlay's own writes for it and tombstone it, which hides
|
|
252
|
+
* every overlay below. The flat layout could only prefix-scan the whole map,
|
|
253
|
+
* 14 ms at 100,000 slots, on every contract creation.
|
|
254
|
+
*
|
|
255
|
+
* Revert-safe by construction: both effects live in the TOP overlay, so a
|
|
256
|
+
* clear inside a checkpoint that is later reverted disappears with it.
|
|
257
|
+
*
|
|
258
|
+
* The parameter is OPTIONAL for an irritating reason that is itself a symptom
|
|
259
|
+
* of the upstream bug: the base class declares `clearStorage()` with ZERO
|
|
260
|
+
* parameters, and TypeScript refuses an override that ADDS a required one
|
|
261
|
+
* (TS2416). Callers reaching us through `StateManagerInterface` always pass an
|
|
262
|
+
* address, because THAT declares `clearStorage(address)`. A no-argument call
|
|
263
|
+
* keeps the base's do-nothing behaviour rather than guessing which account was
|
|
264
|
+
* meant.
|
|
265
|
+
*/
|
|
266
|
+
clearStorage(address?: Address): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Delete an account AND the storage that belonged to it.
|
|
269
|
+
*
|
|
270
|
+
* THE STORAGE HALF IS OURS, and it is the second gap in the same upstream
|
|
271
|
+
* shape as the `clearStorage` no-op above. `SimpleStateManager.deleteAccount`
|
|
272
|
+
* tombstones the account and never touches storage — it has no per-account
|
|
273
|
+
* index to clear with — so a `SELFDESTRUCT` (or an EIP-161 empty-account
|
|
274
|
+
* clearing) left every slot of the dead account READABLE at its address, and
|
|
275
|
+
* `dumpState` kept serialising them. Measured through the node's own surface:
|
|
276
|
+
* after a contract that writes slot 0 and selfdestructs in the same
|
|
277
|
+
* transaction, `eth_getStorageAt` answered `0x2a` in `stateMode:'none'` and
|
|
278
|
+
* `0x0` in `stateMode:'trie'`
|
|
279
|
+
* (`docs/spikes/revm-write-callbacks-reproduce-the-post-state/measurements.md`).
|
|
280
|
+
*
|
|
281
|
+
* A DELETED ACCOUNT HAS NO STORAGE, in a trie by construction: the account is
|
|
282
|
+
* removed and its storage trie goes with it, which is why
|
|
283
|
+
* `MerkleStateManager` needs no equivalent line and why `'trie'` was already
|
|
284
|
+
* right. This makes `'none'` say the same thing rather than leaving the two
|
|
285
|
+
* modes disagreeing about a destroyed contract, and it is the reason the revm
|
|
286
|
+
* engine — whose host is handed `clearStorage` then `removeAccount` for exactly
|
|
287
|
+
* these two cases, with revm's commit semantics already applied — now leaves
|
|
288
|
+
* post-state a diff cannot tell apart from `@ethereumjs/vm`'s. See
|
|
289
|
+
* `docs/adr/0007-we-override-simplestatemanagers-no-op-clearstorage.md`, whose
|
|
290
|
+
* amendment records this decision and what it changes for the DEFAULT engine.
|
|
291
|
+
*
|
|
292
|
+
* Still O(1), and revert-safe for the same reason {@link clearStorageAt} is:
|
|
293
|
+
* the tombstone lands in the TOP overlay, beside the account tombstone the base
|
|
294
|
+
* class writes into the top account frame, so both disappear together if the
|
|
295
|
+
* frame is reverted.
|
|
296
|
+
*/
|
|
297
|
+
deleteAccount(address: Address): Promise<void>;
|
|
298
|
+
/**
|
|
299
|
+
* Every live storage slot, grouped by account, flattened across the whole
|
|
300
|
+
* overlay stack — the view `dumpState` serialises.
|
|
301
|
+
*
|
|
302
|
+
* Bottom-up, applying each overlay's clears before its writes, so the result is
|
|
303
|
+
* what {@link storageAt} would answer for every key. Iteration order is
|
|
304
|
+
* insertion order (accounts in first-write order, slots likewise), which is the
|
|
305
|
+
* order the flat map produced, so the serialised `dumpState` output is
|
|
306
|
+
* byte-identical to the pre-overlay node's for the same state.
|
|
307
|
+
*
|
|
308
|
+
* THE KEYS COME BACK AS `0x`-HEX, not as the packed keys the overlays hold.
|
|
309
|
+
* This is the boundary where the internal format stops: `dumpState` output is
|
|
310
|
+
* PERSISTED data (IndexedDB, `loadState` fixtures) with existing state behind
|
|
311
|
+
* it, and `test/storage-overlay.spec.ts` asserts it byte-identical — key order
|
|
312
|
+
* included — against a dump captured before the layout ever changed. So the
|
|
313
|
+
* conversion lives here, on the dump path, rather than costing every read.
|
|
314
|
+
*
|
|
315
|
+
* O(live slots) and allocating, so it is a dump/persist operation, not a read
|
|
316
|
+
* path. Read one slot with {@link storageAt}.
|
|
317
|
+
*/
|
|
318
|
+
liveStorage(): Map<HexKey, Map<HexKey, Uint8Array>>;
|
|
319
|
+
/**
|
|
320
|
+
* An INDEPENDENT copy. Overlays are cloned two levels deep (the stack, each
|
|
321
|
+
* overlay's outer map and each inner map), because the copy's overlays are not
|
|
322
|
+
* this object's: sharing an inner map would let a write on the copy land in
|
|
323
|
+
* this manager's committed state.
|
|
324
|
+
*/
|
|
325
|
+
shallowCopy(): OverlayStorageStateManager;
|
|
326
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