@gas-killer/analyzer-wasm 0.2.0 → 0.3.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/gas_killer_wasm.d.ts +23 -0
- package/gas_killer_wasm.js +39 -0
- package/gas_killer_wasm_bg.wasm +0 -0
- package/package.json +2 -1
package/gas_killer_wasm.d.ts
CHANGED
|
@@ -10,6 +10,12 @@ export interface AnalyzeTraceResult {
|
|
|
10
10
|
reentered: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export interface PrestateAnalysis {
|
|
14
|
+
eligible: boolean;
|
|
15
|
+
reason: string | null;
|
|
16
|
+
result: AnalyzeTraceResult | null;
|
|
17
|
+
}
|
|
18
|
+
|
|
13
19
|
export interface EncodeTraceResult {
|
|
14
20
|
encoded_updates: string;
|
|
15
21
|
state_update_count: number;
|
|
@@ -26,6 +32,22 @@ export interface EstimateGasResult {
|
|
|
26
32
|
|
|
27
33
|
|
|
28
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Analyze a transaction from its `prestateTracer` diff and `callTracer` frame instead of its
|
|
37
|
+
* struct-log trace, for calls that admit the prestate net form.
|
|
38
|
+
*
|
|
39
|
+
* `diff_json` is the `result` of `debug_traceTransaction` with
|
|
40
|
+
* `{"tracer":"prestateTracer","tracerConfig":{"diffMode":true}}`, and `call_frame_json` the
|
|
41
|
+
* `result` with `{"tracer":"callTracer","tracerConfig":{"withLog":true}}`.
|
|
42
|
+
*
|
|
43
|
+
* `consumer_address` is the transaction's target contract (its `to`). The other arguments are as
|
|
44
|
+
* for [`analyze_trace`].
|
|
45
|
+
*
|
|
46
|
+
* Returns a JS object with `eligible`, and either `result` (shaped like [`analyze_trace`]'s) or
|
|
47
|
+
* `reason`, why the call has no net form; analyze its struct-log trace with [`analyze_trace`] then.
|
|
48
|
+
*/
|
|
49
|
+
export function analyze_prestate(diff_json: string, call_frame_json: string, consumer_address: string, estimator_address: string, caller_address: string, estimate_state_changes_block_number?: bigint | null): any;
|
|
50
|
+
|
|
29
51
|
/**
|
|
30
52
|
* Analyze a Geth trace: parse state updates, ABI-encode them, and estimate gas.
|
|
31
53
|
*
|
|
@@ -67,6 +89,7 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
67
89
|
|
|
68
90
|
export interface InitOutput {
|
|
69
91
|
readonly memory: WebAssembly.Memory;
|
|
92
|
+
readonly analyze_prestate: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: bigint) => [number, number, number];
|
|
70
93
|
readonly analyze_trace: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint, i: number, j: number) => [number, number, number];
|
|
71
94
|
readonly encode_trace: (a: number, b: number) => [number, number, number];
|
|
72
95
|
readonly estimate_gas_heuristic: (a: number, b: number, c: number, d: number) => [number, number, number];
|
package/gas_killer_wasm.js
CHANGED
|
@@ -97,6 +97,45 @@ if (!('encodeInto' in cachedTextEncoder)) {
|
|
|
97
97
|
|
|
98
98
|
let WASM_VECTOR_LEN = 0;
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Analyze a transaction from its `prestateTracer` diff and `callTracer` frame instead of its
|
|
102
|
+
* struct-log trace, for calls that admit the prestate net form.
|
|
103
|
+
*
|
|
104
|
+
* `diff_json` is the `result` of `debug_traceTransaction` with
|
|
105
|
+
* `{"tracer":"prestateTracer","tracerConfig":{"diffMode":true}}`, and `call_frame_json` the
|
|
106
|
+
* `result` with `{"tracer":"callTracer","tracerConfig":{"withLog":true}}`.
|
|
107
|
+
*
|
|
108
|
+
* `consumer_address` is the transaction's target contract (its `to`). The other arguments are as
|
|
109
|
+
* for [`analyze_trace`].
|
|
110
|
+
*
|
|
111
|
+
* Returns a JS object with `eligible`, and either `result` (shaped like [`analyze_trace`]'s) or
|
|
112
|
+
* `reason`, why the call has no net form; analyze its struct-log trace with [`analyze_trace`] then.
|
|
113
|
+
* @param {string} diff_json
|
|
114
|
+
* @param {string} call_frame_json
|
|
115
|
+
* @param {string} consumer_address
|
|
116
|
+
* @param {string} estimator_address
|
|
117
|
+
* @param {string} caller_address
|
|
118
|
+
* @param {bigint | null} [estimate_state_changes_block_number]
|
|
119
|
+
* @returns {any}
|
|
120
|
+
*/
|
|
121
|
+
export function analyze_prestate(diff_json, call_frame_json, consumer_address, estimator_address, caller_address, estimate_state_changes_block_number) {
|
|
122
|
+
const ptr0 = passStringToWasm0(diff_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
123
|
+
const len0 = WASM_VECTOR_LEN;
|
|
124
|
+
const ptr1 = passStringToWasm0(call_frame_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
125
|
+
const len1 = WASM_VECTOR_LEN;
|
|
126
|
+
const ptr2 = passStringToWasm0(consumer_address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
127
|
+
const len2 = WASM_VECTOR_LEN;
|
|
128
|
+
const ptr3 = passStringToWasm0(estimator_address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
129
|
+
const len3 = WASM_VECTOR_LEN;
|
|
130
|
+
const ptr4 = passStringToWasm0(caller_address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
131
|
+
const len4 = WASM_VECTOR_LEN;
|
|
132
|
+
const ret = wasm.analyze_prestate(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, !isLikeNone(estimate_state_changes_block_number), isLikeNone(estimate_state_changes_block_number) ? BigInt(0) : estimate_state_changes_block_number);
|
|
133
|
+
if (ret[2]) {
|
|
134
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
135
|
+
}
|
|
136
|
+
return takeFromExternrefTable0(ret[0]);
|
|
137
|
+
}
|
|
138
|
+
|
|
100
139
|
/**
|
|
101
140
|
* Analyze a Geth trace: parse state updates, ABI-encode them, and estimate gas.
|
|
102
141
|
*
|
package/gas_killer_wasm_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gas-killer/analyzer-wasm",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"
|
|
4
|
+
"description": "Gas Killer's WebAssembly gas analyzer: estimates a transaction's gas savings from its Geth trace in the browser",
|
|
5
|
+
"version": "0.3.0",
|
|
5
6
|
"files": [
|
|
6
7
|
"gas_killer_wasm_bg.wasm",
|
|
7
8
|
"gas_killer_wasm.js",
|