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
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* revm-state-store.ts — a SYNCHRONOUS `StateStore` (revm-wasm) over the node's
|
|
3
|
+
* live `SimpleStateManager`, with NO state copied across and NO state owned.
|
|
4
|
+
*
|
|
5
|
+
* READ AND WRITE, both on demand. The engine reads accounts, code, storage and
|
|
6
|
+
* block hashes as an opcode needs them, and a COMMITTING execute writes back
|
|
7
|
+
* ONLY the accounts revm touched and the slots that changed. There is no bulk
|
|
8
|
+
* sync in either direction and no second copy of state anywhere, which is what
|
|
9
|
+
* keeps the cost proportional to what a transaction touched and why `dumpState`,
|
|
10
|
+
* `loadState`, persistence and the `evm_set*` cheats keep working untouched. See
|
|
11
|
+
* `docs/adr/0010-revm-reads-and-writes-through-host-callbacks-the-node-keeps-owning-state.md`
|
|
12
|
+
* for the ownership decision, its measured cost and the caveat that cuts against
|
|
13
|
+
* it.
|
|
14
|
+
*
|
|
15
|
+
* ## The coupling this buys, stated plainly
|
|
16
|
+
*
|
|
17
|
+
* revm's state reads must be synchronous: the interpreter is a synchronous loop
|
|
18
|
+
* inside wasm and a read happens in the middle of an opcode, so there is no
|
|
19
|
+
* suspension point to await at. Every method on `StateManagerInterface` returns
|
|
20
|
+
* a `Promise`. The ONLY synchronous view of the node's state that exists is the
|
|
21
|
+
* node's own `OverlayStorageStateManager` — `SimpleStateManager`'s two PUBLIC
|
|
22
|
+
* account/code checkpoint stacks plus our storage OVERLAY stack — so this module
|
|
23
|
+
* reaches past the interface into that one implementation, exactly as `node.ts`'s
|
|
24
|
+
* `dumpState` already does in `'none'` mode. The full cost, the alternatives
|
|
25
|
+
* that were rejected, and why `stateMode:'trie'` therefore cannot be served are
|
|
26
|
+
* in `docs/adr/0005-revm-reads-the-nodes-state-through-simplestatemanagers-stacks.md`.
|
|
27
|
+
*
|
|
28
|
+
* Three consequences worth having in your head before editing this file:
|
|
29
|
+
*
|
|
30
|
+
* 1. **Read the TOP of the stack on EVERY access.** A checkpoint pushes a COPY
|
|
31
|
+
* of the account and code maps, so a frame captured once answers from the
|
|
32
|
+
* frame below after the next checkpoint — silently, with no error and
|
|
33
|
+
* plausible values. Storage is read through `storageAt()`, which walks the
|
|
34
|
+
* overlay stack live for the same reason.
|
|
35
|
+
* 2. **The ACCOUNT and CODE key format is the state manager's, not ours**, and
|
|
36
|
+
* must be reproduced byte for byte: `address.toString()`, `0x`-prefixed
|
|
37
|
+
* lowercase hex, because those two stacks are `SimpleStateManager`'s. THE
|
|
38
|
+
* STORAGE KEY IS THE NODE'S (ADR 0009) and is PACKED — two bytes per UTF-16
|
|
39
|
+
* code unit — which is worth 70-73% of every cold access. It is built by
|
|
40
|
+
* `src/storage-keys.ts`, the SAME module `src/state-manager.ts` builds it
|
|
41
|
+
* with, because `@ethereumjs/evm` writes storage through the async
|
|
42
|
+
* `putStorage` while this store reads it through the synchronous `storageAt`:
|
|
43
|
+
* two formats that each work on their own turn every cross-route read into a
|
|
44
|
+
* MISS, and a miss reads as ZERO at identical gas. Storage values are stored
|
|
45
|
+
* in shortest form, so reads left-pad to 32 bytes.
|
|
46
|
+
* 3. **`@ethereumjs/statemanager` is version-pinned deliberately.** Renaming a
|
|
47
|
+
* stack is a compile error here (which is why this file uses the real
|
|
48
|
+
* `OverlayStorageStateManager` type and not `any`); changing the KEY FORMAT or
|
|
49
|
+
* the value padding would compile and return wrong values. {@link assertStateShape}
|
|
50
|
+
* catches the structural half at construction, and the cross-backend gas gate
|
|
51
|
+
* catches the rest, because feeding revm the wrong state changes gas.
|
|
52
|
+
*
|
|
53
|
+
* The `Address` and `Bytes32` arguments on the READ methods are revm's REUSED
|
|
54
|
+
* scratch buffers, valid only for the duration of the call. Everything here
|
|
55
|
+
* consumes them immediately (into a string key, or into a keccak hash); nothing
|
|
56
|
+
* retains one. The WRITE methods receive fresh arrays and may keep them, which
|
|
57
|
+
* is what lets a storage value be stored without a copy.
|
|
58
|
+
*/
|
|
59
|
+
import { Account } from '@ethereumjs/util';
|
|
60
|
+
// THE storage key encoder, shared with the async half in ./state-manager.ts so
|
|
61
|
+
// the two cannot drift into two formats that both work. See its header.
|
|
62
|
+
import { packAddressKey, packSlotKey } from './storage-keys.js';
|
|
63
|
+
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
64
|
+
const HEX = /* @__PURE__ */ (() => {
|
|
65
|
+
const t = [];
|
|
66
|
+
for (let i = 0; i < 256; i++)
|
|
67
|
+
t.push(i.toString(16).padStart(2, '0'));
|
|
68
|
+
return t;
|
|
69
|
+
})();
|
|
70
|
+
/** `0x`-prefixed lowercase hex — the exact key format SimpleStateManager uses. */
|
|
71
|
+
function addrKey(a) {
|
|
72
|
+
let s = '0x';
|
|
73
|
+
for (let i = 0; i < 20; i++)
|
|
74
|
+
s += HEX[a[i]];
|
|
75
|
+
return s;
|
|
76
|
+
}
|
|
77
|
+
function hexOf(b) {
|
|
78
|
+
let s = '';
|
|
79
|
+
for (let i = 0; i < b.length; i++)
|
|
80
|
+
s += HEX[b[i]];
|
|
81
|
+
return s;
|
|
82
|
+
}
|
|
83
|
+
/** SimpleStateManager stores storage values UNPADDED; revm wants 32 bytes. */
|
|
84
|
+
function pad32(v) {
|
|
85
|
+
if (v.length === 32)
|
|
86
|
+
return v;
|
|
87
|
+
const out = new Uint8Array(32);
|
|
88
|
+
out.set(v, 32 - v.length);
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The inverse of {@link pad32}: revm hands over 32 padded bytes and this
|
|
93
|
+
* representation holds the SHORTEST form.
|
|
94
|
+
*
|
|
95
|
+
* Not a micro-optimisation — it is what makes a slot written by revm
|
|
96
|
+
* indistinguishable from the same slot written by `@ethereumjs/evm`, which
|
|
97
|
+
* strips leading zeros itself before `putStorage` (`opcodes/functions.js`, the
|
|
98
|
+
* `SSTORE` case: a zero value becomes a ZERO-LENGTH array, anything else
|
|
99
|
+
* `bigIntToBytes`). `dumpState` serialises the stored bytes verbatim, so a
|
|
100
|
+
* padded write would round-trip correctly and dump differently.
|
|
101
|
+
*/
|
|
102
|
+
function shortest(v) {
|
|
103
|
+
let i = 0;
|
|
104
|
+
while (i < v.length && v[i] === 0)
|
|
105
|
+
i++;
|
|
106
|
+
// A cleared slot is stored EMPTY rather than deleted, exactly as the default
|
|
107
|
+
// engine stores it: `storageAt` stops its overlay walk on a zero-length value,
|
|
108
|
+
// so an overlay below cannot leak a stale value through it.
|
|
109
|
+
return i === 0 ? v : v.subarray(i);
|
|
110
|
+
}
|
|
111
|
+
/** keccak256 of the empty byte string, i.e. the code hash of every EOA. */
|
|
112
|
+
const EMPTY_CODE_HASH_HEX = /* @__PURE__ */ hexOf(keccak_256(new Uint8Array()));
|
|
113
|
+
const EMPTY_CODE = /* @__PURE__ */ new Uint8Array();
|
|
114
|
+
/**
|
|
115
|
+
* Throw unless `sm` still has the exact representation this adapter reads: the
|
|
116
|
+
* two upstream account/code checkpoint stacks AND the node's own storage overlay
|
|
117
|
+
* stack. Cheap, once, at engine construction.
|
|
118
|
+
*
|
|
119
|
+
* IT MUST CONSTRAIN THE REPRESENTATION, NOT MERELY ITS SHELL. Its predecessor
|
|
120
|
+
* asserted "three non-empty arrays of Maps", which a per-account layout satisfied
|
|
121
|
+
* while every storage read silently answered zero — the guard passed on exactly
|
|
122
|
+
* the change it existed to catch (demonstrated in
|
|
123
|
+
* `docs/spikes/spike-storage-layout-cost-for-the-revm-write-half/measurements.md`).
|
|
124
|
+
* So this asserts the storage side by the two ACCESSORS the adapter actually
|
|
125
|
+
* calls plus the overlay stack's own shape, and `test/storage-overlay.spec.ts`
|
|
126
|
+
* feeds it a stock `SimpleStateManager` (the flat layout) to prove it refuses one.
|
|
127
|
+
*/
|
|
128
|
+
export function assertStateShape(sm) {
|
|
129
|
+
for (const name of ['accountStack', 'codeStack']) {
|
|
130
|
+
const stack = sm[name];
|
|
131
|
+
if (!Array.isArray(stack) ||
|
|
132
|
+
stack.length === 0 ||
|
|
133
|
+
!(stack[stack.length - 1] instanceof Map)) {
|
|
134
|
+
throw new Error(`webevm/revm: the state manager does not have the expected ` +
|
|
135
|
+
`SimpleStateManager.${name} (a non-empty array of Maps). The revm engine ` +
|
|
136
|
+
`reads the node's state through those stacks — see ` +
|
|
137
|
+
`docs/adr/0005-revm-reads-the-nodes-state-through-simplestatemanagers-stacks.md. ` +
|
|
138
|
+
`Check the @ethereumjs/statemanager version.`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (typeof sm.storageAt !== 'function' ||
|
|
142
|
+
typeof sm.liveStorage !== 'function' ||
|
|
143
|
+
typeof sm.setStorageAt !== 'function' ||
|
|
144
|
+
typeof sm.clearStorageAt !== 'function') {
|
|
145
|
+
throw new Error('webevm/revm: the state manager does not expose storageAt(), ' +
|
|
146
|
+
"liveStorage(), setStorageAt() and clearStorageAt(), so it is not the node's " +
|
|
147
|
+
'OverlayStorageStateManager. The revm engine reads AND writes storage ' +
|
|
148
|
+
'synchronously through those accessors; a state manager with a different ' +
|
|
149
|
+
'storage representation would answer every slot as ZERO rather than failing. ' +
|
|
150
|
+
'See src/state-manager.ts.');
|
|
151
|
+
}
|
|
152
|
+
const overlays = sm.storageOverlays;
|
|
153
|
+
const top = Array.isArray(overlays)
|
|
154
|
+
? overlays[overlays.length - 1]
|
|
155
|
+
: undefined;
|
|
156
|
+
if (!Array.isArray(overlays) ||
|
|
157
|
+
overlays.length === 0 ||
|
|
158
|
+
!(top?.written instanceof Map) ||
|
|
159
|
+
!(top?.cleared instanceof Set)) {
|
|
160
|
+
throw new Error('webevm/revm: the state manager does not have the expected ' +
|
|
161
|
+
'storageOverlays (a non-empty array whose top overlay has a `written` Map ' +
|
|
162
|
+
'and a `cleared` Set). See src/state-manager.ts.');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* revm's `StateStore`, backed by the node's live state.
|
|
167
|
+
*
|
|
168
|
+
* Created UNBOUND and bound in the engine's `connect(context)`: an injected
|
|
169
|
+
* engine exists before the node does (ADR 0006), and the wasm instance needs its
|
|
170
|
+
* store at instantiation time, so the store is the thing that waits.
|
|
171
|
+
*/
|
|
172
|
+
export class SimpleStateManagerStore {
|
|
173
|
+
#sm;
|
|
174
|
+
#blockHash;
|
|
175
|
+
/** codeHash (unprefixed hex) -> code. Derived, never authoritative. */
|
|
176
|
+
#byCodeHash = new Map();
|
|
177
|
+
/** Code hashes already looked for and NOT found — see {@link beginExecution}. */
|
|
178
|
+
#absentCodeHashes = new Set();
|
|
179
|
+
/**
|
|
180
|
+
* Code handed over by {@link setCode} during the execution now committing,
|
|
181
|
+
* keyed by hash, waiting for the {@link setAccount} that names the address it
|
|
182
|
+
* belongs to.
|
|
183
|
+
*
|
|
184
|
+
* THE BINDING'S COMMIT ORDER IS WHY THIS EXISTS, and it is measured rather than
|
|
185
|
+
* assumed (`docs/spikes/revm-executes-the-first-transaction-with-commit/`):
|
|
186
|
+
* `setCode(codeHash, code)` arrives BEFORE the `setAccount` carrying that hash,
|
|
187
|
+
* because revm's own state is keyed by code HASH while this node keys code by
|
|
188
|
+
* ADDRESS. Nobody but the account change knows the address, so the code waits
|
|
189
|
+
* one callback.
|
|
190
|
+
*
|
|
191
|
+
* Cleared per execution, not per commit: a hash left here would attach a
|
|
192
|
+
* previous transaction's code to an account of the same code hash, which is
|
|
193
|
+
* harmless (the key IS the content hash) but makes the reasoning harder than
|
|
194
|
+
* clearing it.
|
|
195
|
+
*/
|
|
196
|
+
#pendingCode = new Map();
|
|
197
|
+
/**
|
|
198
|
+
* Bind to the node's live state manager. Called once, from `connect`.
|
|
199
|
+
*
|
|
200
|
+
* ONE ENGINE SERVES ONE NODE, and a second bind is refused rather than
|
|
201
|
+
* honoured. An engine instance owns one wasm instance and this one store, so
|
|
202
|
+
* rebinding would re-point an ALREADY-RUNNING node's reads at a different
|
|
203
|
+
* node's state — the first node would then answer every `eth_call` from the
|
|
204
|
+
* second node's accounts, with plausible values and no error. The seam
|
|
205
|
+
* documents `connect` as called exactly once (see `Engine.connect` in
|
|
206
|
+
* ./types.ts), so a second call is a consumer sharing one engine across nodes,
|
|
207
|
+
* and it fails at the second construction rather than at the first wrong read.
|
|
208
|
+
*/
|
|
209
|
+
bind(sm, options = {}) {
|
|
210
|
+
if (this.#sm !== undefined) {
|
|
211
|
+
throw new Error('webevm/revm: this engine is already connected to a node. An ' +
|
|
212
|
+
'engine instance serves ONE node — reconnecting it would re-point the ' +
|
|
213
|
+
"FIRST node's reads at the second node's state, silently. Call " +
|
|
214
|
+
'createRevmEngine() once per createNode(); pass the same compiled ' +
|
|
215
|
+
'WebAssembly.Module to each if you want to compile the wasm only once.');
|
|
216
|
+
}
|
|
217
|
+
assertStateShape(sm);
|
|
218
|
+
this.#sm = sm;
|
|
219
|
+
this.#blockHash = options.blockHash;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Start of one execution — a read-only call OR a committing transaction. Drops
|
|
223
|
+
* the negative code-index cache and any code left waiting for its account.
|
|
224
|
+
*
|
|
225
|
+
* A rebuild-on-miss index cannot cache a miss ACROSS executions: code deployed
|
|
226
|
+
* between two of them would stay invisible, and an invisible contract runs as
|
|
227
|
+
* EMPTY code and returns `success` with empty data — silently wrong (ADR
|
|
228
|
+
* 0005). WITHIN one execution it can, and must, because nothing else can write
|
|
229
|
+
* to the node's state while the interpreter holds the thread: JS runs
|
|
230
|
+
* single-threaded, a read-only call never calls a write method at all, and a
|
|
231
|
+
* transaction's writes all arrive at the END, during commit, after the last
|
|
232
|
+
* opcode. So a hash that is absent at the first opcode is absent at the last,
|
|
233
|
+
* and a contract that is genuinely absent no longer re-scans the whole code map
|
|
234
|
+
* on every access.
|
|
235
|
+
*
|
|
236
|
+
* NOT `beginCall`, which it was called while this store served only `eth_call`:
|
|
237
|
+
* *call* names the seam's READ operation in this codebase (`Engine.call`), and
|
|
238
|
+
* a transaction reaches here too now.
|
|
239
|
+
*/
|
|
240
|
+
beginExecution() {
|
|
241
|
+
this.#absentCodeHashes.clear();
|
|
242
|
+
this.#pendingCode.clear();
|
|
243
|
+
}
|
|
244
|
+
// --- the three top-of-stack views -------------------------------------
|
|
245
|
+
// stack[stack.length - 1] on EVERY access. See the header: a cached frame is
|
|
246
|
+
// stale after the next checkpoint, silently.
|
|
247
|
+
get #accounts() {
|
|
248
|
+
const s = this.#connected().accountStack;
|
|
249
|
+
return s[s.length - 1];
|
|
250
|
+
}
|
|
251
|
+
get #code() {
|
|
252
|
+
const s = this.#connected().codeStack;
|
|
253
|
+
return s[s.length - 1];
|
|
254
|
+
}
|
|
255
|
+
#connected() {
|
|
256
|
+
if (this.#sm === undefined)
|
|
257
|
+
throw new Error('webevm/revm: the engine touched state before connect() bound ' +
|
|
258
|
+
'it to a node. Pass the engine to createNode() before using it.');
|
|
259
|
+
return this.#sm;
|
|
260
|
+
}
|
|
261
|
+
getAccount(address) {
|
|
262
|
+
const acc = this.#accounts.get(addrKey(address));
|
|
263
|
+
if (acc === undefined)
|
|
264
|
+
return undefined;
|
|
265
|
+
return { balance: acc.balance, nonce: acc.nonce, codeHash: acc.codeHash };
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* THE HOT PATH, and the reason `src/storage-keys.ts` exists: a cold access cost
|
|
269
|
+
* 1.31-1.33 µs through the real wasm module with the `0x`-hex key and costs
|
|
270
|
+
* 0.36-0.39 µs with the packed one, of which 0.17-0.18 µs is the wasm crossing
|
|
271
|
+
* itself (`docs/spikes/revm-state-store-packed-storage-keys/measurements.md`).
|
|
272
|
+
* Both keys are packed, both are built here and nowhere else on this side, and
|
|
273
|
+
* `storageAt` walks the overlay stack afresh on every call because the top of it
|
|
274
|
+
* moves under us (see the header's point 1).
|
|
275
|
+
*/
|
|
276
|
+
getStorage(address, slot) {
|
|
277
|
+
const v = this.#connected().storageAt(packAddressKey(address), packSlotKey(slot));
|
|
278
|
+
if (v === undefined || v.length === 0)
|
|
279
|
+
return undefined;
|
|
280
|
+
return pad32(v);
|
|
281
|
+
}
|
|
282
|
+
getCode(codeHash) {
|
|
283
|
+
const key = hexOf(codeHash);
|
|
284
|
+
if (key === EMPTY_CODE_HASH_HEX)
|
|
285
|
+
return EMPTY_CODE;
|
|
286
|
+
const hit = this.#byCodeHash.get(key);
|
|
287
|
+
if (hit !== undefined)
|
|
288
|
+
return hit;
|
|
289
|
+
const pending = this.#pendingCode.get(key);
|
|
290
|
+
if (pending !== undefined)
|
|
291
|
+
return pending;
|
|
292
|
+
if (this.#absentCodeHashes.has(key))
|
|
293
|
+
return undefined;
|
|
294
|
+
this.#reindexCode();
|
|
295
|
+
const rebuilt = this.#byCodeHash.get(key);
|
|
296
|
+
if (rebuilt === undefined)
|
|
297
|
+
this.#absentCodeHashes.add(key);
|
|
298
|
+
return rebuilt;
|
|
299
|
+
}
|
|
300
|
+
getBlockHash(blockNumber) {
|
|
301
|
+
return this.#blockHash?.(blockNumber);
|
|
302
|
+
}
|
|
303
|
+
// --- the write half ------------------------------------------------------
|
|
304
|
+
// ONLY a COMMITTING execute reaches these (`Revm#call` cannot be made to
|
|
305
|
+
// commit, whatever its options say), and they arrive with revm's own commit
|
|
306
|
+
// semantics ALREADY APPLIED: a `SELFDESTRUCT` and an EIP-161 empty-account
|
|
307
|
+
// clearing both arrive as `clearStorage` then `removeAccount`, and a created
|
|
308
|
+
// account arrives with `clearStorage` FIRST so a fresh contract cannot inherit
|
|
309
|
+
// storage from a previous life at its address. None of that is re-derived here;
|
|
310
|
+
// re-deriving it is how a host gets EIP-161 subtly wrong.
|
|
311
|
+
//
|
|
312
|
+
// EACH ONE IS ONE MAP WRITE INTO THE TOP OF THE NODE'S OWN STATE, at the same
|
|
313
|
+
// depth `putAccount` / `putCode` / `putStorage` write to, so a transaction's
|
|
314
|
+
// cost is proportional to what it touched and a `revert()` above still drops it.
|
|
315
|
+
// They are written against the state manager's REPRESENTATION rather than its
|
|
316
|
+
// async interface for the reason in the header: revm's commit runs inside a
|
|
317
|
+
// synchronous wasm callback and every `StateManagerInterface` method returns a
|
|
318
|
+
// `Promise`.
|
|
319
|
+
setAccount(address, account) {
|
|
320
|
+
const accounts = this.#accounts;
|
|
321
|
+
const key = addrKey(address);
|
|
322
|
+
const existing = accounts.get(key);
|
|
323
|
+
// The storage ROOT is carried over rather than computed: `SimpleStateManager`
|
|
324
|
+
// implements no state-root logic at all, so this field never reflects storage
|
|
325
|
+
// on either engine (ADR 0009 records the EIP-7610 consequence). Carrying it
|
|
326
|
+
// keeps a revm-written account byte-identical to an ethereumjs-written one,
|
|
327
|
+
// which is what `dumpState` serialises.
|
|
328
|
+
accounts.set(key, new Account(account.nonce, account.balance, existing?.storageRoot, account.codeHash));
|
|
329
|
+
// The code this account's hash names, if it arrived a callback ago. Written
|
|
330
|
+
// HERE because this is the only callback that knows the address, and only when
|
|
331
|
+
// `setCode` actually ran, which the binding does exactly when revm loaded or
|
|
332
|
+
// deposited code for it — never for an account that merely received ether.
|
|
333
|
+
const hashKey = hexOf(account.codeHash);
|
|
334
|
+
const code = this.#pendingCode.get(hashKey);
|
|
335
|
+
if (code !== undefined)
|
|
336
|
+
this.#code.set(key, code);
|
|
337
|
+
}
|
|
338
|
+
setCode(codeHash, code) {
|
|
339
|
+
// This one method writes only into the store's OWN index (the address it
|
|
340
|
+
// belongs to arrives with the next `setAccount`), so it would otherwise be the
|
|
341
|
+
// one write that an UNBOUND store accepted in silence.
|
|
342
|
+
this.#connected();
|
|
343
|
+
const key = hexOf(codeHash);
|
|
344
|
+
this.#pendingCode.set(key, code);
|
|
345
|
+
// A hash that was absent a moment ago exists now, so the negative cache must
|
|
346
|
+
// forget it or a contract created inside this transaction would read as EMPTY
|
|
347
|
+
// code in the next one.
|
|
348
|
+
this.#absentCodeHashes.delete(key);
|
|
349
|
+
this.#byCodeHash.set(key, code);
|
|
350
|
+
}
|
|
351
|
+
setStorage(address, slot, value) {
|
|
352
|
+
this.#connected().setStorageAt(packAddressKey(address), packSlotKey(slot), shortest(value));
|
|
353
|
+
}
|
|
354
|
+
clearStorage(address) {
|
|
355
|
+
this.#connected().clearStorageAt(packAddressKey(address));
|
|
356
|
+
}
|
|
357
|
+
removeAccount(address) {
|
|
358
|
+
// A TOMBSTONE, not a delete, because that is what `deleteAccount` does
|
|
359
|
+
// upstream (`SimpleStateManager` sets the key to `undefined`) and this store
|
|
360
|
+
// must leave the node's state in the shape the default engine leaves it: a
|
|
361
|
+
// `delete` would let an overlay-free account map answer from nothing while a
|
|
362
|
+
// tombstone answers "absent", and `dumpState` skips both. The account's CODE is
|
|
363
|
+
// deliberately left where it is, again matching upstream, which never removes
|
|
364
|
+
// it either; nothing reads it, since revm asks for code by HASH.
|
|
365
|
+
//
|
|
366
|
+
// THE STORAGE HALF IS NOT DONE HERE and must not be: the binding sends
|
|
367
|
+
// `clearStorage` for this account IMMEDIATELY BEFORE this call, for a
|
|
368
|
+
// `SELFDESTRUCT` and for an EIP-161 clearing alike, so doing it again here
|
|
369
|
+
// would be the host re-deriving a rule the engine already applied. The DEFAULT
|
|
370
|
+
// engine reached the same end state only after `OverlayStorageStateManager`
|
|
371
|
+
// learned to clear storage on `deleteAccount` (ADR 0007's 2026-08-10
|
|
372
|
+
// amendment); before that it left a dead contract's slots readable, and the
|
|
373
|
+
// two engines' post-state differed on exactly this.
|
|
374
|
+
this.#accounts.set(addrKey(address), undefined);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Rebuild codeHash -> code from the live code map. The node keys code by
|
|
378
|
+
* ADDRESS; revm asks by HASH, so somebody has to hold the inverse, and it is
|
|
379
|
+
* derived state living outside the state manager.
|
|
380
|
+
*
|
|
381
|
+
* Rebuilt on a MISS (and only on a miss), so the cost is one keccak per
|
|
382
|
+
* account-with-code per newly-deployed contract, not per read. Rebuild-on-miss
|
|
383
|
+
* rather than a hook on `putCode`, because code reaches the state manager by
|
|
384
|
+
* several routes (`evm_setCode`, `loadState`, a contract creation inside a
|
|
385
|
+
* transaction) and a hook can be forgotten by the next one. A hash that HITS
|
|
386
|
+
* can never be wrong: the key IS the content hash.
|
|
387
|
+
*/
|
|
388
|
+
#reindexCode() {
|
|
389
|
+
this.#byCodeHash.clear();
|
|
390
|
+
for (const c of this.#code.values())
|
|
391
|
+
this.#byCodeHash.set(hexOf(keccak_256(c)), c);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
//# sourceMappingURL=revm-state-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revm-state-store.js","sourceRoot":"","sources":["../src/revm-state-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,OAAO,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AAEzC,+EAA+E;AAC/E,wEAAwE;AACxE,OAAO,EAAC,cAAc,EAAE,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAGjD,MAAM,GAAG,GAAG,eAAe,CAAC,CAAC,GAAG,EAAE;IACjC,MAAM,CAAC,GAAa,EAAE,CAAC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C,OAAO,CAAC,EACvB,WAAW,CAAC,IAAI,CAAC,EACjB,QAAQ,CAAC,KAAK,CAAC,CACf,CAAC;IACH,CAAC;IAED,YAAY,CAAC,OAAgB;QAC5B,IAAI,CAAC,UAAU,EAAE,CAAC,cAAc,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,aAAa,CAAC,OAAgB;QAC7B,uEAAuE;QACvE,6EAA6E;QAC7E,2EAA2E;QAC3E,6EAA6E;QAC7E,gFAAgF;QAChF,8EAA8E;QAC9E,iEAAiE;QACjE,EAAE;QACF,uEAAuE;QACvE,sEAAsE;QACtE,2EAA2E;QAC3E,+EAA+E;QAC/E,4EAA4E;QAC5E,qEAAqE;QACrE,4EAA4E;QAC5E,oDAAoD;QACpD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC;IACjD,CAAC;IAED;;;;;;;;;;;OAWG;IACH,YAAY;QACX,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACzB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YAClC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAChD,CAAC;CACD"}
|
package/dist/revm.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { type SpecName, type WasmSource } from 'revm-wasm';
|
|
2
|
+
import type { Engine } from './types.js';
|
|
3
|
+
/** This engine's stable identifier, as reported by `node.engine.id`. */
|
|
4
|
+
export declare const REVM_ENGINE_ID = "revm-wasm";
|
|
5
|
+
export interface RevmEngineOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The `revm-wasm` module: bytes, a `URL`, a string URL, a `Response`, or an
|
|
8
|
+
* already-compiled `WebAssembly.Module` (the one to prefer when several nodes
|
|
9
|
+
* share one compilation). Passed through to `revm-wasm` untouched.
|
|
10
|
+
*/
|
|
11
|
+
wasm: WasmSource;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* ethereumjs hardfork name -> revm spec: the hardforks this engine ADMITS.
|
|
15
|
+
*
|
|
16
|
+
* The node runs Cancun today and nothing here can change that, so this table is
|
|
17
|
+
* a GUARD rather than a feature: if the node's hardfork ever moves, an engine
|
|
18
|
+
* that silently kept running Cancun rules would charge different gas from the
|
|
19
|
+
* default engine and nothing would say so.
|
|
20
|
+
*
|
|
21
|
+
* WHAT MAKES A FORK ADMISSIBLE is not that revm has a spec for it, and it is not
|
|
22
|
+
* that the node and revm AGREE about it either. Agreement is necessary and not
|
|
23
|
+
* sufficient: everything the node computes ABOUT a transaction — today the
|
|
24
|
+
* shared intrinsic-gas arithmetic in ./intrinsic-gas.ts, and the read budget
|
|
25
|
+
* assembled in `call` below — must (a) still agree with what revm ENFORCES under
|
|
26
|
+
* that spec, and (b) be what the PROTOCOL charges at that fork, judged by
|
|
27
|
+
* something that is neither of the two. Clause (b) is not decoration: the engine
|
|
28
|
+
* SUBTRACTS `intrinsicGas()` from what revm spent and the node adds the same
|
|
29
|
+
* number back, so the two sides agree about intrinsic gas by construction and a
|
|
30
|
+
* term that is wrong at a fork is wrong on both sides at once.
|
|
31
|
+
*
|
|
32
|
+
* Prague and Osaka fail (a). Berlin, London and Paris once failed (b) — both
|
|
33
|
+
* this node and `revm-wasm@0.3.0` charged EIP-3860's initcode word cost there,
|
|
34
|
+
* and EIP-3860 arrived in Shanghai. `revm-wasm@0.3.1` fixed its half, and
|
|
35
|
+
* ./intrinsic-gas.ts now gates the term on the node's `Common`, so all three are
|
|
36
|
+
* back.
|
|
37
|
+
*
|
|
38
|
+
* ADDING A FORK BELOW BERLIN COSTS MORE THAN A LINE HERE. ./intrinsic-gas.ts is
|
|
39
|
+
* protocol-correct over Istanbul..Cancun only: it hardcodes EIP-2028's 16 gas per
|
|
40
|
+
* non-zero calldata byte, which was 68 before Istanbul, so a pre-Istanbul entry in
|
|
41
|
+
* this table would make `eth_estimateGas` UNDER-estimate by 52 gas per non-zero
|
|
42
|
+
* byte — and a client uses an estimate as the transaction's gas limit. Anything
|
|
43
|
+
* in NEITHER table is refused by the unknown-fork guard in `connect` below, which
|
|
44
|
+
* is what keeps that unreachable today. Gate the term the way EIP-3860's is gated
|
|
45
|
+
* first, then move the entry; the clause-(b) assertions in
|
|
46
|
+
* `test/revm-engine.spec.ts` measure that boundary from both sides and will fail
|
|
47
|
+
* the build otherwise. See {@link REVM_REFUSED_HARDFORKS} and
|
|
48
|
+
* `docs/adr/0008-the-revm-engine-admits-only-hardforks-it-can-cost.md`.
|
|
49
|
+
* Anything not in either table is refused by name.
|
|
50
|
+
*
|
|
51
|
+
* FROZEN, AND NOT MERELY `Readonly`. The type annotation is erased at runtime, so
|
|
52
|
+
* until this was frozen a consumer could re-admit a refused fork with a single
|
|
53
|
+
* assignment through the export (`REVM_SPEC_BY_HARDFORK.prague = 'PRAGUE'`) and
|
|
54
|
+
* `connect` below would wave it through — an `eth_estimateGas` revm itself then
|
|
55
|
+
* rejects (`GasFloorMoreThanGasLimit`). A guard a stray assignment removes is
|
|
56
|
+
* weaker than it reads, and these tables are PUBLIC precisely so the admitted set
|
|
57
|
+
* can be read without provoking a throw, which is a reading surface, not an
|
|
58
|
+
* editing one. The freeze is shallow and that is total here: every value is a
|
|
59
|
+
* string. Asserted in `test/revm-engine.spec.ts` as a RUNTIME property (both
|
|
60
|
+
* tables frozen, a re-admitting edit leaves them unchanged, and the guard still
|
|
61
|
+
* refuses the fork afterwards), because a type cannot be measured.
|
|
62
|
+
*
|
|
63
|
+
* THE DECISION UNDER THAT, since the alternative was live: freezing is enough,
|
|
64
|
+
* and `connect` deliberately keeps reading these objects rather than a snapshot
|
|
65
|
+
* taken at module load. A snapshot would make the GUARD robust while leaving the
|
|
66
|
+
* EXPORT a lie — a consumer who assigned `prague` would read a table saying
|
|
67
|
+
* `prague` is served while every read of it was refused, i.e. two answers to the
|
|
68
|
+
* one question these exports exist to answer. It would also fork the truth in
|
|
69
|
+
* two: the table a reader inspects and the table the guard consults, kept in step
|
|
70
|
+
* by nothing. Freezing removes the divergence at its source instead of tolerating
|
|
71
|
+
* it, and it fails at the CONSUMER's own line (a `TypeError` under strict mode,
|
|
72
|
+
* a dropped write under sloppy mode) rather than silently somewhere else. If a
|
|
73
|
+
* later table ever has to be built at runtime rather than written literally here,
|
|
74
|
+
* freeze it at the end of construction; do not reach for the snapshot.
|
|
75
|
+
*/
|
|
76
|
+
export declare const REVM_SPEC_BY_HARDFORK: Readonly<Record<string, SpecName>>;
|
|
77
|
+
/**
|
|
78
|
+
* Hardforks revm HAS a spec for and this engine still refuses, each with the
|
|
79
|
+
* reason quoted verbatim in the refusal.
|
|
80
|
+
*
|
|
81
|
+
* These are the silent-wrong-answer cases. From Prague on, revm ENFORCES rules
|
|
82
|
+
* the node's own arithmetic does not implement, so `eth_estimateGas` could return
|
|
83
|
+
* a number the engine that produced it would REJECT — and viem uses that number
|
|
84
|
+
* as the transaction's gas limit. A loud refusal at construction is the honest
|
|
85
|
+
* edge (ADR 0004); a plausible estimate is not.
|
|
86
|
+
*
|
|
87
|
+
* To admit one of these, make the node's arithmetic BOTH agree with revm under
|
|
88
|
+
* that spec AND match the protocol at that fork: implement the missing rule in
|
|
89
|
+
* ./intrinsic-gas.ts and in the read budget here, then prove it against the
|
|
90
|
+
* engine and move the entry to {@link REVM_SPEC_BY_HARDFORK}. Note that the
|
|
91
|
+
* EIP-7623 floor is not a TERM of the intrinsic-gas formula but a floor on the
|
|
92
|
+
* transaction's total, so unlike the EIP-3860 fork gate it cannot be threaded
|
|
93
|
+
* through ./intrinsic-gas.ts alone — both callers have to learn about it. The
|
|
94
|
+
* measurements behind each line are in
|
|
95
|
+
* `docs/spikes/prague-intrinsic-gas-floor-or-refuse/` and
|
|
96
|
+
* `docs/spikes/intrinsic-gas-charges-eip-3860-on-forks-that-predate-it/` (§6 for
|
|
97
|
+
* the re-measurement on `revm-wasm@0.3.1`, which left both of these standing).
|
|
98
|
+
*
|
|
99
|
+
* FROZEN for the same reason as {@link REVM_SPEC_BY_HARDFORK}, where the freeze
|
|
100
|
+
* decision (and why the guard reads these objects rather than a load-time
|
|
101
|
+
* snapshot) is recorded: deleting an entry here is the other half of the
|
|
102
|
+
* one-assignment re-admission the freeze exists to refuse.
|
|
103
|
+
*/
|
|
104
|
+
export declare const REVM_REFUSED_HARDFORKS: Readonly<Record<string, string>>;
|
|
105
|
+
/**
|
|
106
|
+
* Build a revm-backed engine, serving BOTH halves of the seam: `call` for the
|
|
107
|
+
* node's reads and `transact` for the transactions it mines and commits (see the
|
|
108
|
+
* module header for how the two differ, which is validity and nothing else).
|
|
109
|
+
*
|
|
110
|
+
* The wasm is fetched and compiled HERE, so a consumer can start the download
|
|
111
|
+
* while the UI paints and hand the finished engine to `createNode()` afterwards.
|
|
112
|
+
* The engine binds to the node's state later, through the seam's
|
|
113
|
+
* `connect(context)` hook (ADR 0006: an injected engine exists before the node
|
|
114
|
+
* does, so it cannot capture anything at construction).
|
|
115
|
+
*
|
|
116
|
+
* ONE ENGINE PER NODE. The returned engine binds to the first node it is given
|
|
117
|
+
* to and REFUSES a second, because rebinding would silently re-point the first
|
|
118
|
+
* node's reads and transactions at the second node's state. To pay the wasm
|
|
119
|
+
* compilation only once, compile it yourself and pass the same
|
|
120
|
+
* `WebAssembly.Module` to each `createRevmEngine()` call — that is what the
|
|
121
|
+
* `wasm` option accepting a compiled module is for.
|
|
122
|
+
*/
|
|
123
|
+
export declare function createRevmEngine(options: RevmEngineOptions): Promise<Engine>;
|
|
124
|
+
//# sourceMappingURL=revm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revm.d.ts","sourceRoot":"","sources":["../src/revm.ts"],"names":[],"mappings":"AAyDA,OAAO,EAAa,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAC,MAAM,WAAW,CAAC;AAIrE,OAAO,KAAK,EACX,MAAM,EAMN,MAAM,YAAY,CAAC;AAEpB,wEAAwE;AACxE,eAAO,MAAM,cAAc,cAAc,CAAC;AAE1C,MAAM,WAAW,iBAAiB;IACjC;;;;OAIG;IACH,IAAI,EAAE,UAAU,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAOlE,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAejE,CAAC;AAEJ;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,gBAAgB,CACrC,OAAO,EAAE,iBAAiB,GACxB,OAAO,CAAC,MAAM,CAAC,CAyajB"}
|