webevm 0.9.1 → 0.10.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/README.md +94 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/intrinsic-gas.d.ts +70 -14
- package/dist/intrinsic-gas.d.ts.map +1 -1
- package/dist/intrinsic-gas.js +65 -0
- package/dist/intrinsic-gas.js.map +1 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +686 -41
- package/dist/node.js.map +1 -1
- package/dist/revm.d.ts +18 -17
- package/dist/revm.d.ts.map +1 -1
- package/dist/revm.js +80 -40
- package/dist/revm.js.map +1 -1
- package/dist/state-manager.d.ts +19 -0
- package/dist/state-manager.d.ts.map +1 -1
- package/dist/state-manager.js +32 -0
- package/dist/state-manager.js.map +1 -1
- package/dist/types.d.ts +39 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/worker-host.d.ts +30 -0
- package/dist/worker-host.d.ts.map +1 -1
- package/dist/worker-host.js +42 -5
- package/dist/worker-host.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/intrinsic-gas.ts +92 -14
- package/src/node.ts +864 -44
- package/src/revm.ts +103 -47
- package/src/state-manager.ts +35 -0
- package/src/types.ts +40 -0
- package/src/worker-host.ts +79 -7
package/dist/worker-host.js
CHANGED
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
* itself: it enumerates the keys of a reference node INSTANCE, and an optional
|
|
29
29
|
* field that instance does not carry is invisible to it.
|
|
30
30
|
*
|
|
31
|
-
* A MISUSE OF {@link WorkerHostOptions.createEngine}
|
|
31
|
+
* A MISUSE OF {@link WorkerHostOptions.createEngine} (or of
|
|
32
|
+
* {@link WorkerHostOptions.createNode}) IS A VALUE, NEVER A THROW,
|
|
32
33
|
* and that ordering is the whole of why: `expose()` registers comlink's message
|
|
33
34
|
* listener, so a module that throws BEFORE reaching it answers the main thread
|
|
34
35
|
* nothing at all and `createWorkerNode()` stays pending forever. The refusal is
|
|
@@ -98,7 +99,7 @@ function nodeProxy(node) {
|
|
|
98
99
|
* of your own; this is the same object `worker-entry` exposes.
|
|
99
100
|
*/
|
|
100
101
|
export function createNodeWorkerApi(hostOptions = {}) {
|
|
101
|
-
const { createEngine } = hostOptions;
|
|
102
|
+
const { createEngine, createNode: nodeFactory } = hostOptions;
|
|
102
103
|
// THE REFUSAL IS A VALUE. Passing the ENGINE (or the promise of one) where its
|
|
103
104
|
// FACTORY belongs is the one plausible mistake at this seam, and it is refused
|
|
104
105
|
// with a real message rather than left to become a `TypeError` from inside
|
|
@@ -107,7 +108,14 @@ export function createNodeWorkerApi(hostOptions = {}) {
|
|
|
107
108
|
// the worker registers no message listener, and an awaited `createWorkerNode()`
|
|
108
109
|
// on the main thread never settles at all. Recorded here, said out loud here,
|
|
109
110
|
// and thrown where a caller can catch it.
|
|
110
|
-
|
|
111
|
+
//
|
|
112
|
+
// Both options are checked, and a module that gets BOTH wrong hears about both
|
|
113
|
+
// at once rather than fixing one only to meet the other.
|
|
114
|
+
const refusals = [
|
|
115
|
+
engineSupplierRefusal(createEngine),
|
|
116
|
+
nodeFactoryRefusal(nodeFactory),
|
|
117
|
+
].filter((r) => r !== undefined);
|
|
118
|
+
const refusal = refusals.length > 0 ? refusals.join('\n') : undefined;
|
|
111
119
|
// THE EARLY SIGNAL, on the thread the mistake was written on and at the moment
|
|
112
120
|
// it was made: a developer with the worker console open reads it before anybody
|
|
113
121
|
// asks for a node. It is not the only one, precisely because a bundled app's
|
|
@@ -122,8 +130,14 @@ export function createNodeWorkerApi(hostOptions = {}) {
|
|
|
122
130
|
if (refusal !== undefined)
|
|
123
131
|
throw new Error(refusal);
|
|
124
132
|
// The main thread's options pass through UNCHANGED; the engine, and only
|
|
125
|
-
// the engine, is this thread's.
|
|
126
|
-
|
|
133
|
+
// the engine, is this thread's. Then whichever factory makes the node:
|
|
134
|
+
// the consumer's when given (a throw or rejection from it crosses to the
|
|
135
|
+
// main thread as `createWorkerNode()`'s rejection), webevm's own
|
|
136
|
+
// otherwise.
|
|
137
|
+
const nodeOptions = createEngine
|
|
138
|
+
? { ...options, engine: await createEngine() }
|
|
139
|
+
: options;
|
|
140
|
+
const node = await (nodeFactory ?? createNode)(nodeOptions);
|
|
127
141
|
return proxy(nodeProxy(node));
|
|
128
142
|
},
|
|
129
143
|
};
|
|
@@ -155,6 +169,29 @@ function engineSupplierRefusal(createEngine) {
|
|
|
155
169
|
'Pass `{createEngine: () => createRevmEngine({wasm})}`, i.e. a function that returns the engine, rather than an engine you built already. ' +
|
|
156
170
|
why);
|
|
157
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* The message for a `createNode` factory that is not a function, or `undefined`
|
|
174
|
+
* when it is one (`undefined` itself being webevm's own `createNode`).
|
|
175
|
+
*
|
|
176
|
+
* The THENABLE case names itself for the same reason it does for `createEngine`:
|
|
177
|
+
* `createNode: createDevNode({...})` (no arrow) built a node at module scope and
|
|
178
|
+
* passed the promise of it, one arrow away from right, and a node built there
|
|
179
|
+
* would not even have the main thread's options.
|
|
180
|
+
*/
|
|
181
|
+
function nodeFactoryRefusal(nodeFactory) {
|
|
182
|
+
if (nodeFactory === undefined || typeof nodeFactory === 'function') {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
const why = "It is called ONCE PER createNode(), with the main thread's options (the engine merged in when `createEngine` is set), and the node it resolves to is the one the main thread drives.";
|
|
186
|
+
if (typeof nodeFactory?.then === 'function') {
|
|
187
|
+
return ('webevm/worker-host: `createNode` must be a FUNCTION that creates the node from the options it is given, and it was given a PROMISE of one: the factory was CALLED here instead of being passed. ' +
|
|
188
|
+
'Write `{createNode: (options) => myCreateNode(options)}`, not `{createNode: myCreateNode(...)}`. ' +
|
|
189
|
+
why);
|
|
190
|
+
}
|
|
191
|
+
return (`webevm/worker-host: \`createNode\` must be a FUNCTION that creates the node from the options it is given (received ${describe(nodeFactory)}). ` +
|
|
192
|
+
"Pass `{createNode: (options) => myCreateNode(options)}`, or omit it for webevm's own createNode. " +
|
|
193
|
+
why);
|
|
194
|
+
}
|
|
158
195
|
/** What was passed, in one word a reader can match against their own code. */
|
|
159
196
|
function describe(value) {
|
|
160
197
|
if (value === null)
|
package/dist/worker-host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-host.js","sourceRoot":"","sources":["../src/worker-host.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"worker-host.js","sourceRoot":"","sources":["../src/worker-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,OAAO,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,SAAS,CAAC;AACtC,OAAO,EAAC,UAAU,EAAC,MAAM,WAAW,CAAC;AAErC,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAkEvD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAS,SAAS,CAAC,IAAc;IAChC,MAAM,SAAS,GAAuB;QACrC,OAAO,EAAE,gBAAgB,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACvD,IAAI,EAAE,gBAAgB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACzC,SAAS,EAAE,gBAAgB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;QACnD,SAAS,EAAE,gBAAgB,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC7D,YAAY,EAAE,gBAAgB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;QACzD,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;QACvC,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,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;IACxL,IAAI,OAAQ,WAAuC,EAAE,IAAI,KAAK,UAAU,EAAE,CAAC;QAC1E,OAAO,CACN,kMAAkM;YAClM,mGAAmG;YACnG,GAAG,CACH,CAAC;IACH,CAAC;IACD,OAAO,CACN,sHAAsH,QAAQ,CAAC,WAAW,CAAC,KAAK;QAChJ,mGAAmG;QACnG,GAAG,CACH,CAAC;AACH,CAAC;AAED,8EAA8E;AAC9E,SAAS,QAAQ,CAAC,KAAc;IAC/B,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC;IAC5C,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC;IAC1B,OAAO,GAAG,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;AACpD,CAAC;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,UAAU,CAAC,cAAiC,EAAE;IAC7D,MAAM,GAAG,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,CAAC,GAAG,CAAC,CAAC;IACZ,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webevm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Slim, execution-only in-browser EIP-1193 Ethereum node on @ethereumjs/vm. Transport-agnostic core + optional comlink Worker helpers + IndexedDB persistence.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ethereum",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@ethereumjs/util": "^10.1.2",
|
|
66
66
|
"@ethereumjs/vm": "^10.1.2",
|
|
67
67
|
"@noble/hashes": "^2.2.0",
|
|
68
|
-
"revm-wasm": "^0.
|
|
68
|
+
"revm-wasm": "^0.5.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"comlink": "^4.4.2"
|
package/src/index.ts
CHANGED
package/src/intrinsic-gas.ts
CHANGED
|
@@ -48,19 +48,28 @@
|
|
|
48
48
|
* Shanghai, which is precisely the drift this file exists to prevent. See
|
|
49
49
|
* `docs/adr/0008-the-revm-engine-admits-only-hardforks-it-can-cost.md`.
|
|
50
50
|
*
|
|
51
|
-
* THE FORK RANGE THIS FORMULA IS TRUE FOR IS ISTANBUL..
|
|
52
|
-
* AT BOTH SIDES. The node runs Cancun
|
|
53
|
-
* Berlin..
|
|
54
|
-
* measured against the protocol at every admitted fork by the
|
|
55
|
-
* assertions in `test/revm-engine.spec.ts`; the two ends are where the
|
|
56
|
-
* stops being true, so they are what anyone moving the node's hardfork
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* (
|
|
51
|
+
* THE FORK RANGE THIS FORMULA IS TRUE FOR IS ISTANBUL..OSAKA, AND IT HAS AN END
|
|
52
|
+
* AT BOTH SIDES. The node runs Cancun, Prague or Osaka (`NodeOptions.hardfork`);
|
|
53
|
+
* `webevm/revm` admits Berlin..Osaka, which sits strictly inside that range.
|
|
54
|
+
* Every term above is measured against the protocol at every admitted fork by the
|
|
55
|
+
* clause-(b) assertions in `test/revm-engine.spec.ts`; the two ends are where the
|
|
56
|
+
* formula stops being true, so they are what anyone moving the node's hardfork
|
|
57
|
+
* owes.
|
|
58
|
+
*
|
|
59
|
+
* FROM PRAGUE ON, THREE MORE RULES, AND NONE OF THEM IS A TERM OF THIS FORMULA.
|
|
60
|
+
* EIP-7623's calldata floor ({@link calldataFloorGas}) bounds a transaction's
|
|
61
|
+
* TOTAL from below, EIP-7825's cap ({@link transactionGasLimitCap}, Osaka) bounds
|
|
62
|
+
* its gas LIMIT from above, and EIP-7702's per-authorization charge
|
|
63
|
+
* ({@link authorizationListGas}) is paid only by a transaction that carries an
|
|
64
|
+
* authorization list, which a read request never does. So they sit BESIDE this
|
|
65
|
+
* formula and are applied by the node alone, above the engine seam: the node
|
|
66
|
+
* never hands an engine a read whose total is below the floor, and the one number
|
|
67
|
+
* an engine needs, this one, is unchanged. Moving intrinsic gas
|
|
68
|
+
* onto the seam's read request instead was evaluated and rejected; see
|
|
69
|
+
* `docs/adr/0015-the-forks-gas-rules-on-the-read-path-are-the-nodes-admission-and-intrinsic-gas-stays-off-the-seam.md`.
|
|
70
|
+
* AT AMSTERDAM the formula stops being true (EIP-8037 splits intrinsic gas into
|
|
71
|
+
* two dimensions, EIP-7976 re-prices calldata tokens), which is why that fork is
|
|
72
|
+
* refused by name.
|
|
64
73
|
*
|
|
65
74
|
* BELOW, AT ISTANBUL: the 16 above is EIP-2028's, which shipped in Istanbul, and
|
|
66
75
|
* it is hardcoded here rather than gated. Before Istanbul a non-zero calldata
|
|
@@ -70,7 +79,8 @@
|
|
|
70
79
|
* The term is NOT fork-gated on purpose: no admitted fork predates Istanbul and
|
|
71
80
|
* none can, because a fork in neither of ./revm.ts's two tables is refused by the
|
|
72
81
|
* "no revm spec is known" guard, so a gate would be arithmetic nothing can reach
|
|
73
|
-
* (the
|
|
82
|
+
* (the argument that once kept the EIP-7623 floor out, before a hardfork option
|
|
83
|
+
* made it reachable). What stands in its place
|
|
74
84
|
* is a measurement rather than a comment: the suite measures this term either
|
|
75
85
|
* side of the Istanbul boundary (`petersburg` and `istanbul`), so re-admitting a
|
|
76
86
|
* pre-Istanbul fork turns that measured disagreement into a failing build. If one
|
|
@@ -115,6 +125,74 @@ export function intrinsicGas(
|
|
|
115
125
|
return gas;
|
|
116
126
|
}
|
|
117
127
|
|
|
128
|
+
/** EIP-7623: what one calldata TOKEN costs under the floor. */
|
|
129
|
+
const TOTAL_COST_FLOOR_PER_TOKEN = 10n;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* EIP-7623 (Prague): THE LEAST A TRANSACTION WITH THIS CALLDATA PAYS, whatever it
|
|
133
|
+
* executes: `21000 + 10 * tokens`, a zero byte being one token and a non-zero byte
|
|
134
|
+
* four. `0n` on a fork without EIP-7623, so a caller can take `max(.., floor)`
|
|
135
|
+
* unconditionally.
|
|
136
|
+
*
|
|
137
|
+
* A FLOOR ON THE TOTAL, NOT A TERM. A transaction is charged
|
|
138
|
+
* `max(intrinsic + execution - refund, floor)`, and its gas LIMIT must be at
|
|
139
|
+
* least the floor before it may start (`INTRINSIC_GAS_TOO_LOW` on
|
|
140
|
+
* `@ethereumjs/vm`, `GasFloorMoreThanGasLimit` on revm,
|
|
141
|
+
* `insufficient gas for floor data gas cost` on geth). The access list does not
|
|
142
|
+
* enter it at Prague or Osaka (EIP-7981, which adds it, is Amsterdam's).
|
|
143
|
+
*
|
|
144
|
+
* Gated on the node's `Common` by `isActivatedEIP(7623)`, for the reason the
|
|
145
|
+
* EIP-3860 term above is: that is the table `runTx` consults when it applies the
|
|
146
|
+
* same floor to a mined transaction.
|
|
147
|
+
*/
|
|
148
|
+
export function calldataFloorGas(data: Uint8Array, common: Common): bigint {
|
|
149
|
+
if (!common.isActivatedEIP(7623)) return 0n;
|
|
150
|
+
let tokens = 0n;
|
|
151
|
+
for (const b of data) tokens += b === 0 ? 1n : 4n;
|
|
152
|
+
return 21_000n + TOTAL_COST_FLOOR_PER_TOKEN * tokens;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** EIP-7825 (Osaka): the largest gas limit a single transaction may carry. */
|
|
156
|
+
const MAX_TRANSACTION_GAS_LIMIT = 16_777_216n;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* EIP-7825 (Osaka): THE LARGEST GAS LIMIT ONE TRANSACTION MAY CARRY, 2^24, or
|
|
160
|
+
* `undefined` on a fork without the cap. A limit above it is refused outright by
|
|
161
|
+
* every party (`@ethereumjs/tx` at construction, revm with
|
|
162
|
+
* `TxGasLimitGreaterThanCap`, geth with `transaction gas limit too high`); it is
|
|
163
|
+
* never trimmed. The node applies it to what it ADMITS and RECOMMENDS: a
|
|
164
|
+
* transaction above it is refused at submit, and `eth_estimateGas` never searches
|
|
165
|
+
* above it. A READ is not held to it, as geth's `eth_call` is not: the default
|
|
166
|
+
* engine's `runCall` never enforced it, and the revm engine lifts it on its reads
|
|
167
|
+
* (`disableTxGasLimitCap`).
|
|
168
|
+
*/
|
|
169
|
+
export function transactionGasLimitCap(common: Common): bigint | undefined {
|
|
170
|
+
return common.isActivatedEIP(7825) ? MAX_TRANSACTION_GAS_LIMIT : undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** EIP-7702: what one authorization costs up front (`PER_EMPTY_ACCOUNT_COST`). */
|
|
174
|
+
const PER_AUTHORIZATION_COST = 25_000n;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* WHAT AN `eth_estimateGas` REQUEST'S EIP-7702 AUTHORIZATION LIST COSTS UP FRONT:
|
|
178
|
+
* 25,000 per entry, the charge a type-4 transaction pays before its first opcode
|
|
179
|
+
* (`@ethereumjs/tx`'s `getIntrinsicGas()` includes it, which is the floor the
|
|
180
|
+
* node refuses a submitted transaction against). The 12,500 refunded for an
|
|
181
|
+
* authority that already exists is NOT subtracted: the estimate over-states by
|
|
182
|
+
* that much, which is the safe direction for a number a client uses as a gas
|
|
183
|
+
* limit.
|
|
184
|
+
*
|
|
185
|
+
* Beside {@link intrinsicGas} rather than inside it for the reason
|
|
186
|
+
* {@link accessListGas} is: the engine seam's read request carries no
|
|
187
|
+
* authorization list, so a term in the shared formula would be subtracted by the
|
|
188
|
+
* revm engine from a figure that never contained it. `0n` for anything that is
|
|
189
|
+
* not an array, so an untyped request cannot make an estimate throw here.
|
|
190
|
+
*/
|
|
191
|
+
export function authorizationListGas(authorizationList: unknown): bigint {
|
|
192
|
+
if (!Array.isArray(authorizationList)) return 0n;
|
|
193
|
+
return BigInt(authorizationList.length) * PER_AUTHORIZATION_COST;
|
|
194
|
+
}
|
|
195
|
+
|
|
118
196
|
/** EIP-2930: what one access-list entry's ADDRESS costs, up front. */
|
|
119
197
|
const ACCESS_LIST_ADDRESS_COST = 2_400n;
|
|
120
198
|
/** EIP-2930: what one access-list STORAGE KEY costs, up front. */
|