@lucid-evolution/uplc 0.3.0 → 0.4.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 +39 -2
- package/dist/size/browser/uplc_tx.d.ts +71 -0
- package/dist/size/browser/uplc_tx_bg.js +279 -17
- package/dist/size/browser/uplc_tx_bg.wasm +0 -0
- package/dist/size/browser/uplc_tx_bg.wasm.d.ts +38 -0
- package/dist/size/node/uplc_tx.d.ts +71 -0
- package/dist/size/node/uplc_tx.js +277 -16
- package/dist/size/node/uplc_tx_bg.wasm +0 -0
- package/dist/size/node/uplc_tx_bg.wasm.d.ts +38 -0
- package/dist/speed/browser/uplc_tx.d.ts +71 -0
- package/dist/speed/browser/uplc_tx_bg.js +279 -17
- package/dist/speed/browser/uplc_tx_bg.wasm +0 -0
- package/dist/speed/browser/uplc_tx_bg.wasm.d.ts +38 -0
- package/dist/speed/node/uplc_tx.d.ts +71 -0
- package/dist/speed/node/uplc_tx.js +277 -16
- package/dist/speed/node/uplc_tx_bg.wasm +0 -0
- package/dist/speed/node/uplc_tx_bg.wasm.d.ts +38 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -28,7 +28,44 @@ pnpm build
|
|
|
28
28
|
|
|
29
29
|
The package ships two builds of the evaluator:
|
|
30
30
|
|
|
31
|
-
- **speed** (`-O3`, ~1.
|
|
32
|
-
- **size** (`-Oz`, ~
|
|
31
|
+
- **speed** (`-O3`, ~1.93 MB wasm): faster script evaluation.
|
|
32
|
+
- **size** (`-Oz`, ~1.03 MB wasm): smaller download.
|
|
33
33
|
|
|
34
34
|
`@lucid-evolution/uplc` resolves to the speed build on Node, Bun and Deno, and to the size build in browser bundles and edge runtimes (`browser`, `worker`, `workerd` and `edge-light` export conditions). To pick a variant explicitly, import `@lucid-evolution/uplc/speed` or `@lucid-evolution/uplc/size`.
|
|
35
|
+
|
|
36
|
+
## Evaluating a program
|
|
37
|
+
|
|
38
|
+
`eval_program_raw` evaluates a UPLC program applied to `Data` arguments, outside of any transaction. The caller builds whatever arguments the program expects, including its script context.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { eval_program_raw } from "@lucid-evolution/uplc";
|
|
42
|
+
|
|
43
|
+
const result = eval_program_raw(
|
|
44
|
+
programFlat, // Uint8Array: the program, flat-encoded without a CBOR wrapper
|
|
45
|
+
[datum, redeemer, context], // Uint8Array[]: each argument as CBOR-encoded Data
|
|
46
|
+
3, // Plutus version: 1, 2 or 3
|
|
47
|
+
11, // protocol major version: 5 to 11
|
|
48
|
+
costModel, // BigInt64Array: every cost model parameter for this Plutus version
|
|
49
|
+
10_000_000_000n, // CPU budget
|
|
50
|
+
14_000_000n, // memory budget
|
|
51
|
+
true, // charge every step, and stop as soon as the budget runs out
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
result.ok; // whether the program succeeded (for Plutus V3, returned unit)
|
|
55
|
+
result.error_kind; // 0 ok, 1 over budget, 2 failed, 3 Plutus V3 result not unit
|
|
56
|
+
result.cpu; // bigint
|
|
57
|
+
result.mem; // bigint
|
|
58
|
+
result.logs; // string[]: the program's traces
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
With `false` as the last argument, steps are charged and the budget is checked every 200 steps as the ledger does. That only changes the cost reported for a program that fails, as the ledger does not charge the steps it took since the budget was last checked; the Haskell evaluator reports the same cost. It throws only when the inputs are malformed or unsupported.
|
|
62
|
+
|
|
63
|
+
`uplc_build_info()` returns JSON that describes the build: the uplc crate it was built from, the latest protocol version it supports, each Plutus version's cost model length, a digest of what a fixed set of programs evaluate to, and whether those programs give the expected results (`"selfTest": "pass"`).
|
|
64
|
+
|
|
65
|
+
## Tests
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pnpm test
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`test/fixtures/programs.json` holds programs with their outcome and cost under Plutus V3 and protocol version 11, as given by the Haskell evaluator (plutus-core 1.71).
|
|
@@ -16,3 +16,74 @@ export function apply_params_to_script(
|
|
|
16
16
|
params_bytes: Uint8Array,
|
|
17
17
|
plutus_script_bytes: Uint8Array,
|
|
18
18
|
): Uint8Array;
|
|
19
|
+
/**
|
|
20
|
+
* Evaluates a UPLC program applied to Data arguments, outside of any
|
|
21
|
+
* transaction: the caller builds whatever arguments the program expects,
|
|
22
|
+
* including its script context.
|
|
23
|
+
*
|
|
24
|
+
* - `program_flat`: the program, flat-encoded without a CBOR wrapper.
|
|
25
|
+
* - `args_cbor`: the arguments, each one CBOR-encoded Data, applied in order.
|
|
26
|
+
* - `language`: the Plutus version to evaluate as, 1, 2 or 3.
|
|
27
|
+
* - `protocol_major_version`: the protocol version whose semantics to use,
|
|
28
|
+
* from 5 (Alonzo) to 12 (Dijkstra).
|
|
29
|
+
* - `cost_model`: the cost model parameters, every one the evaluator knows
|
|
30
|
+
* for this Plutus version (350 for Plutus V3), in the ledger's order.
|
|
31
|
+
* - `budget_cpu`, `budget_mem`: the budget.
|
|
32
|
+
* - `strict_budget`: charge every step as the machine takes it, and stop the
|
|
33
|
+
* program as soon as it goes over budget, instead of charging steps and
|
|
34
|
+
* checking the budget every 200 steps as the ledger does. Only the cost of a
|
|
35
|
+
* program that fails differs: the ledger does not charge the steps it took
|
|
36
|
+
* since the budget was last checked.
|
|
37
|
+
*
|
|
38
|
+
* Fails only when the inputs are malformed or unsupported. A program that fails
|
|
39
|
+
* is an [`EvalProgramResult`] that is not `ok`.
|
|
40
|
+
*/
|
|
41
|
+
export function eval_program_raw(
|
|
42
|
+
program_flat: Uint8Array,
|
|
43
|
+
args_cbor: Uint8Array[],
|
|
44
|
+
language: number,
|
|
45
|
+
protocol_major_version: number,
|
|
46
|
+
cost_model: BigInt64Array,
|
|
47
|
+
budget_cpu: bigint,
|
|
48
|
+
budget_mem: bigint,
|
|
49
|
+
strict_budget: boolean,
|
|
50
|
+
): EvalProgramResult;
|
|
51
|
+
/**
|
|
52
|
+
* Describes this build of the evaluator as JSON: the uplc crate it was built
|
|
53
|
+
* from, the length of each Plutus version's cost model, and a digest of what a
|
|
54
|
+
* fixed set of programs evaluate to, with their costs, under Plutus V3 and the
|
|
55
|
+
* latest protocol version. Two builds with the same digest agree on those
|
|
56
|
+
* programs; `selfTest` says whether this one gives the expected results.
|
|
57
|
+
*/
|
|
58
|
+
export function uplc_build_info(): string;
|
|
59
|
+
/**
|
|
60
|
+
* The outcome of [`eval_program_raw`].
|
|
61
|
+
*/
|
|
62
|
+
export class EvalProgramResult {
|
|
63
|
+
private constructor();
|
|
64
|
+
free(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Whether the program succeeded: it did not fail and, for Plutus V3, it
|
|
67
|
+
* returned unit.
|
|
68
|
+
*/
|
|
69
|
+
ok: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* The CPU the program used. A program that went over budget is charged
|
|
72
|
+
* what it used up to the point where the machine stopped it.
|
|
73
|
+
*/
|
|
74
|
+
cpu: bigint;
|
|
75
|
+
/**
|
|
76
|
+
* The memory the program used.
|
|
77
|
+
*/
|
|
78
|
+
mem: bigint;
|
|
79
|
+
/**
|
|
80
|
+
* Why the program did not succeed: 0 when it did, 1 when it went over
|
|
81
|
+
* budget, 2 when it failed in any other way and 3 when a Plutus V3 program
|
|
82
|
+
* returned something other than unit.
|
|
83
|
+
*/
|
|
84
|
+
error_kind: number;
|
|
85
|
+
/**
|
|
86
|
+
* The messages the program traced, in order.
|
|
87
|
+
*/
|
|
88
|
+
logs: string[];
|
|
89
|
+
}
|
|
@@ -4,11 +4,7 @@ export function __wbg_set_wasm(val) {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
10
|
-
|
|
11
|
-
cachedTextDecoder.decode();
|
|
7
|
+
let WASM_VECTOR_LEN = 0;
|
|
12
8
|
|
|
13
9
|
let cachedUint8ArrayMemory0 = null;
|
|
14
10
|
|
|
@@ -19,20 +15,66 @@ function getUint8ArrayMemory0() {
|
|
|
19
15
|
return cachedUint8ArrayMemory0;
|
|
20
16
|
}
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
|
|
19
|
+
|
|
20
|
+
let cachedTextEncoder = new lTextEncoder('utf-8');
|
|
21
|
+
|
|
22
|
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
23
|
+
? function (arg, view) {
|
|
24
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
25
25
|
}
|
|
26
|
+
: function (arg, view) {
|
|
27
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
28
|
+
view.set(buf);
|
|
29
|
+
return {
|
|
30
|
+
read: arg.length,
|
|
31
|
+
written: buf.length
|
|
32
|
+
};
|
|
33
|
+
});
|
|
26
34
|
|
|
27
|
-
|
|
35
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
28
36
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
if (realloc === undefined) {
|
|
38
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
39
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
40
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
41
|
+
WASM_VECTOR_LEN = buf.length;
|
|
42
|
+
return ptr;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let len = arg.length;
|
|
46
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
47
|
+
|
|
48
|
+
const mem = getUint8ArrayMemory0();
|
|
49
|
+
|
|
50
|
+
let offset = 0;
|
|
51
|
+
|
|
52
|
+
for (; offset < len; offset++) {
|
|
53
|
+
const code = arg.charCodeAt(offset);
|
|
54
|
+
if (code > 0x7F) break;
|
|
55
|
+
mem[ptr + offset] = code;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (offset !== len) {
|
|
59
|
+
if (offset !== 0) {
|
|
60
|
+
arg = arg.slice(offset);
|
|
61
|
+
}
|
|
62
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
63
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
64
|
+
const ret = encodeString(arg, view);
|
|
65
|
+
|
|
66
|
+
offset += ret.written;
|
|
67
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
WASM_VECTOR_LEN = offset;
|
|
33
71
|
return ptr;
|
|
34
72
|
}
|
|
35
73
|
|
|
74
|
+
function isLikeNone(x) {
|
|
75
|
+
return x === undefined || x === null;
|
|
76
|
+
}
|
|
77
|
+
|
|
36
78
|
let cachedDataViewMemory0 = null;
|
|
37
79
|
|
|
38
80
|
function getDataViewMemory0() {
|
|
@@ -42,6 +84,24 @@ function getDataViewMemory0() {
|
|
|
42
84
|
return cachedDataViewMemory0;
|
|
43
85
|
}
|
|
44
86
|
|
|
87
|
+
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
|
|
88
|
+
|
|
89
|
+
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
90
|
+
|
|
91
|
+
cachedTextDecoder.decode();
|
|
92
|
+
|
|
93
|
+
function getStringFromWasm0(ptr, len) {
|
|
94
|
+
ptr = ptr >>> 0;
|
|
95
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
99
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
100
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
101
|
+
WASM_VECTOR_LEN = arg.length;
|
|
102
|
+
return ptr;
|
|
103
|
+
}
|
|
104
|
+
|
|
45
105
|
function addToExternrefTable0(obj) {
|
|
46
106
|
const idx = wasm.__externref_table_alloc();
|
|
47
107
|
wasm.__wbindgen_export_0.set(idx, obj);
|
|
@@ -58,10 +118,6 @@ function passArrayJsValueToWasm0(array, malloc) {
|
|
|
58
118
|
return ptr;
|
|
59
119
|
}
|
|
60
120
|
|
|
61
|
-
function isLikeNone(x) {
|
|
62
|
-
return x === undefined || x === null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
121
|
function takeFromExternrefTable0(idx) {
|
|
66
122
|
const value = wasm.__wbindgen_export_0.get(idx);
|
|
67
123
|
wasm.__externref_table_dealloc(idx);
|
|
@@ -132,6 +188,203 @@ export function apply_params_to_script(params_bytes, plutus_script_bytes) {
|
|
|
132
188
|
return v3;
|
|
133
189
|
}
|
|
134
190
|
|
|
191
|
+
let cachedBigUint64ArrayMemory0 = null;
|
|
192
|
+
|
|
193
|
+
function getBigUint64ArrayMemory0() {
|
|
194
|
+
if (cachedBigUint64ArrayMemory0 === null || cachedBigUint64ArrayMemory0.byteLength === 0) {
|
|
195
|
+
cachedBigUint64ArrayMemory0 = new BigUint64Array(wasm.memory.buffer);
|
|
196
|
+
}
|
|
197
|
+
return cachedBigUint64ArrayMemory0;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function passArray64ToWasm0(arg, malloc) {
|
|
201
|
+
const ptr = malloc(arg.length * 8, 8) >>> 0;
|
|
202
|
+
getBigUint64ArrayMemory0().set(arg, ptr / 8);
|
|
203
|
+
WASM_VECTOR_LEN = arg.length;
|
|
204
|
+
return ptr;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Evaluates a UPLC program applied to Data arguments, outside of any
|
|
208
|
+
* transaction: the caller builds whatever arguments the program expects,
|
|
209
|
+
* including its script context.
|
|
210
|
+
*
|
|
211
|
+
* - `program_flat`: the program, flat-encoded without a CBOR wrapper.
|
|
212
|
+
* - `args_cbor`: the arguments, each one CBOR-encoded Data, applied in order.
|
|
213
|
+
* - `language`: the Plutus version to evaluate as, 1, 2 or 3.
|
|
214
|
+
* - `protocol_major_version`: the protocol version whose semantics to use,
|
|
215
|
+
* from 5 (Alonzo) to 12 (Dijkstra).
|
|
216
|
+
* - `cost_model`: the cost model parameters, every one the evaluator knows
|
|
217
|
+
* for this Plutus version (350 for Plutus V3), in the ledger's order.
|
|
218
|
+
* - `budget_cpu`, `budget_mem`: the budget.
|
|
219
|
+
* - `strict_budget`: charge every step as the machine takes it, and stop the
|
|
220
|
+
* program as soon as it goes over budget, instead of charging steps and
|
|
221
|
+
* checking the budget every 200 steps as the ledger does. Only the cost of a
|
|
222
|
+
* program that fails differs: the ledger does not charge the steps it took
|
|
223
|
+
* since the budget was last checked.
|
|
224
|
+
*
|
|
225
|
+
* Fails only when the inputs are malformed or unsupported. A program that fails
|
|
226
|
+
* is an [`EvalProgramResult`] that is not `ok`.
|
|
227
|
+
* @param {Uint8Array} program_flat
|
|
228
|
+
* @param {Uint8Array[]} args_cbor
|
|
229
|
+
* @param {number} language
|
|
230
|
+
* @param {number} protocol_major_version
|
|
231
|
+
* @param {BigInt64Array} cost_model
|
|
232
|
+
* @param {bigint} budget_cpu
|
|
233
|
+
* @param {bigint} budget_mem
|
|
234
|
+
* @param {boolean} strict_budget
|
|
235
|
+
* @returns {EvalProgramResult}
|
|
236
|
+
*/
|
|
237
|
+
export function eval_program_raw(program_flat, args_cbor, language, protocol_major_version, cost_model, budget_cpu, budget_mem, strict_budget) {
|
|
238
|
+
const ptr0 = passArray8ToWasm0(program_flat, wasm.__wbindgen_malloc);
|
|
239
|
+
const len0 = WASM_VECTOR_LEN;
|
|
240
|
+
const ptr1 = passArrayJsValueToWasm0(args_cbor, wasm.__wbindgen_malloc);
|
|
241
|
+
const len1 = WASM_VECTOR_LEN;
|
|
242
|
+
const ptr2 = passArray64ToWasm0(cost_model, wasm.__wbindgen_malloc);
|
|
243
|
+
const len2 = WASM_VECTOR_LEN;
|
|
244
|
+
const ret = wasm.eval_program_raw(ptr0, len0, ptr1, len1, language, protocol_major_version, ptr2, len2, budget_cpu, budget_mem, strict_budget);
|
|
245
|
+
if (ret[2]) {
|
|
246
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
247
|
+
}
|
|
248
|
+
return EvalProgramResult.__wrap(ret[0]);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Describes this build of the evaluator as JSON: the uplc crate it was built
|
|
253
|
+
* from, the length of each Plutus version's cost model, and a digest of what a
|
|
254
|
+
* fixed set of programs evaluate to, with their costs, under Plutus V3 and the
|
|
255
|
+
* latest protocol version. Two builds with the same digest agree on those
|
|
256
|
+
* programs; `selfTest` says whether this one gives the expected results.
|
|
257
|
+
* @returns {string}
|
|
258
|
+
*/
|
|
259
|
+
export function uplc_build_info() {
|
|
260
|
+
let deferred1_0;
|
|
261
|
+
let deferred1_1;
|
|
262
|
+
try {
|
|
263
|
+
const ret = wasm.uplc_build_info();
|
|
264
|
+
deferred1_0 = ret[0];
|
|
265
|
+
deferred1_1 = ret[1];
|
|
266
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
267
|
+
} finally {
|
|
268
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const EvalProgramResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
273
|
+
? { register: () => {}, unregister: () => {} }
|
|
274
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_evalprogramresult_free(ptr >>> 0, 1));
|
|
275
|
+
/**
|
|
276
|
+
* The outcome of [`eval_program_raw`].
|
|
277
|
+
*/
|
|
278
|
+
export class EvalProgramResult {
|
|
279
|
+
|
|
280
|
+
static __wrap(ptr) {
|
|
281
|
+
ptr = ptr >>> 0;
|
|
282
|
+
const obj = Object.create(EvalProgramResult.prototype);
|
|
283
|
+
obj.__wbg_ptr = ptr;
|
|
284
|
+
EvalProgramResultFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
285
|
+
return obj;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
__destroy_into_raw() {
|
|
289
|
+
const ptr = this.__wbg_ptr;
|
|
290
|
+
this.__wbg_ptr = 0;
|
|
291
|
+
EvalProgramResultFinalization.unregister(this);
|
|
292
|
+
return ptr;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
free() {
|
|
296
|
+
const ptr = this.__destroy_into_raw();
|
|
297
|
+
wasm.__wbg_evalprogramresult_free(ptr, 0);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Whether the program succeeded: it did not fail and, for Plutus V3, it
|
|
301
|
+
* returned unit.
|
|
302
|
+
* @returns {boolean}
|
|
303
|
+
*/
|
|
304
|
+
get ok() {
|
|
305
|
+
const ret = wasm.__wbg_get_evalprogramresult_ok(this.__wbg_ptr);
|
|
306
|
+
return ret !== 0;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Whether the program succeeded: it did not fail and, for Plutus V3, it
|
|
310
|
+
* returned unit.
|
|
311
|
+
* @param {boolean} arg0
|
|
312
|
+
*/
|
|
313
|
+
set ok(arg0) {
|
|
314
|
+
wasm.__wbg_set_evalprogramresult_ok(this.__wbg_ptr, arg0);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* The CPU the program used. A program that went over budget is charged
|
|
318
|
+
* what it used up to the point where the machine stopped it.
|
|
319
|
+
* @returns {bigint}
|
|
320
|
+
*/
|
|
321
|
+
get cpu() {
|
|
322
|
+
const ret = wasm.__wbg_get_evalprogramresult_cpu(this.__wbg_ptr);
|
|
323
|
+
return BigInt.asUintN(64, ret);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* The CPU the program used. A program that went over budget is charged
|
|
327
|
+
* what it used up to the point where the machine stopped it.
|
|
328
|
+
* @param {bigint} arg0
|
|
329
|
+
*/
|
|
330
|
+
set cpu(arg0) {
|
|
331
|
+
wasm.__wbg_set_evalprogramresult_cpu(this.__wbg_ptr, arg0);
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* The memory the program used.
|
|
335
|
+
* @returns {bigint}
|
|
336
|
+
*/
|
|
337
|
+
get mem() {
|
|
338
|
+
const ret = wasm.__wbg_get_evalprogramresult_mem(this.__wbg_ptr);
|
|
339
|
+
return BigInt.asUintN(64, ret);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* The memory the program used.
|
|
343
|
+
* @param {bigint} arg0
|
|
344
|
+
*/
|
|
345
|
+
set mem(arg0) {
|
|
346
|
+
wasm.__wbg_set_evalprogramresult_mem(this.__wbg_ptr, arg0);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Why the program did not succeed: 0 when it did, 1 when it went over
|
|
350
|
+
* budget, 2 when it failed in any other way and 3 when a Plutus V3 program
|
|
351
|
+
* returned something other than unit.
|
|
352
|
+
* @returns {number}
|
|
353
|
+
*/
|
|
354
|
+
get error_kind() {
|
|
355
|
+
const ret = wasm.__wbg_get_evalprogramresult_error_kind(this.__wbg_ptr);
|
|
356
|
+
return ret;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Why the program did not succeed: 0 when it did, 1 when it went over
|
|
360
|
+
* budget, 2 when it failed in any other way and 3 when a Plutus V3 program
|
|
361
|
+
* returned something other than unit.
|
|
362
|
+
* @param {number} arg0
|
|
363
|
+
*/
|
|
364
|
+
set error_kind(arg0) {
|
|
365
|
+
wasm.__wbg_set_evalprogramresult_error_kind(this.__wbg_ptr, arg0);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* The messages the program traced, in order.
|
|
369
|
+
* @returns {string[]}
|
|
370
|
+
*/
|
|
371
|
+
get logs() {
|
|
372
|
+
const ret = wasm.__wbg_get_evalprogramresult_logs(this.__wbg_ptr);
|
|
373
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
374
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
375
|
+
return v1;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* The messages the program traced, in order.
|
|
379
|
+
* @param {string[]} arg0
|
|
380
|
+
*/
|
|
381
|
+
set logs(arg0) {
|
|
382
|
+
const ptr0 = passArrayJsValueToWasm0(arg0, wasm.__wbindgen_malloc);
|
|
383
|
+
const len0 = WASM_VECTOR_LEN;
|
|
384
|
+
wasm.__wbg_set_evalprogramresult_logs(this.__wbg_ptr, ptr0, len0);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
135
388
|
export function __wbg_buffer_609cc3eee51ed158(arg0) {
|
|
136
389
|
const ret = arg0.buffer;
|
|
137
390
|
return ret;
|
|
@@ -172,6 +425,15 @@ export function __wbindgen_memory() {
|
|
|
172
425
|
return ret;
|
|
173
426
|
};
|
|
174
427
|
|
|
428
|
+
export function __wbindgen_string_get(arg0, arg1) {
|
|
429
|
+
const obj = arg1;
|
|
430
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
431
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
432
|
+
var len1 = WASM_VECTOR_LEN;
|
|
433
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
434
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
435
|
+
};
|
|
436
|
+
|
|
175
437
|
export function __wbindgen_string_new(arg0, arg1) {
|
|
176
438
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
177
439
|
return ret;
|
|
Binary file
|
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_evalprogramresult_free: (a: number, b: number) => void;
|
|
5
|
+
export const __wbg_get_evalprogramresult_cpu: (a: number) => bigint;
|
|
6
|
+
export const __wbg_get_evalprogramresult_error_kind: (a: number) => number;
|
|
7
|
+
export const __wbg_get_evalprogramresult_logs: (a: number) => [number, number];
|
|
8
|
+
export const __wbg_get_evalprogramresult_mem: (a: number) => bigint;
|
|
9
|
+
export const __wbg_get_evalprogramresult_ok: (a: number) => number;
|
|
10
|
+
export const __wbg_set_evalprogramresult_cpu: (a: number, b: bigint) => void;
|
|
11
|
+
export const __wbg_set_evalprogramresult_error_kind: (
|
|
12
|
+
a: number,
|
|
13
|
+
b: number,
|
|
14
|
+
) => void;
|
|
15
|
+
export const __wbg_set_evalprogramresult_logs: (
|
|
16
|
+
a: number,
|
|
17
|
+
b: number,
|
|
18
|
+
c: number,
|
|
19
|
+
) => void;
|
|
20
|
+
export const __wbg_set_evalprogramresult_mem: (a: number, b: bigint) => void;
|
|
21
|
+
export const __wbg_set_evalprogramresult_ok: (a: number, b: number) => void;
|
|
4
22
|
export const apply_params_to_script: (
|
|
5
23
|
a: number,
|
|
6
24
|
b: number,
|
|
@@ -24,8 +42,28 @@ export const eval_phase_two_raw: (
|
|
|
24
42
|
n: number,
|
|
25
43
|
o: number,
|
|
26
44
|
) => [number, number, number, number];
|
|
45
|
+
export const eval_program_raw: (
|
|
46
|
+
a: number,
|
|
47
|
+
b: number,
|
|
48
|
+
c: number,
|
|
49
|
+
d: number,
|
|
50
|
+
e: number,
|
|
51
|
+
f: number,
|
|
52
|
+
g: number,
|
|
53
|
+
h: number,
|
|
54
|
+
i: bigint,
|
|
55
|
+
j: bigint,
|
|
56
|
+
k: number,
|
|
57
|
+
) => [number, number, number];
|
|
58
|
+
export const uplc_build_info: () => [number, number];
|
|
27
59
|
export const __wbindgen_export_0: WebAssembly.Table;
|
|
28
60
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
61
|
+
export const __wbindgen_realloc: (
|
|
62
|
+
a: number,
|
|
63
|
+
b: number,
|
|
64
|
+
c: number,
|
|
65
|
+
d: number,
|
|
66
|
+
) => number;
|
|
29
67
|
export const __externref_table_alloc: () => number;
|
|
30
68
|
export const __externref_table_dealloc: (a: number) => void;
|
|
31
69
|
export const __externref_drop_slice: (a: number, b: number) => void;
|
|
@@ -16,3 +16,74 @@ export function apply_params_to_script(
|
|
|
16
16
|
params_bytes: Uint8Array,
|
|
17
17
|
plutus_script_bytes: Uint8Array,
|
|
18
18
|
): Uint8Array;
|
|
19
|
+
/**
|
|
20
|
+
* Evaluates a UPLC program applied to Data arguments, outside of any
|
|
21
|
+
* transaction: the caller builds whatever arguments the program expects,
|
|
22
|
+
* including its script context.
|
|
23
|
+
*
|
|
24
|
+
* - `program_flat`: the program, flat-encoded without a CBOR wrapper.
|
|
25
|
+
* - `args_cbor`: the arguments, each one CBOR-encoded Data, applied in order.
|
|
26
|
+
* - `language`: the Plutus version to evaluate as, 1, 2 or 3.
|
|
27
|
+
* - `protocol_major_version`: the protocol version whose semantics to use,
|
|
28
|
+
* from 5 (Alonzo) to 12 (Dijkstra).
|
|
29
|
+
* - `cost_model`: the cost model parameters, every one the evaluator knows
|
|
30
|
+
* for this Plutus version (350 for Plutus V3), in the ledger's order.
|
|
31
|
+
* - `budget_cpu`, `budget_mem`: the budget.
|
|
32
|
+
* - `strict_budget`: charge every step as the machine takes it, and stop the
|
|
33
|
+
* program as soon as it goes over budget, instead of charging steps and
|
|
34
|
+
* checking the budget every 200 steps as the ledger does. Only the cost of a
|
|
35
|
+
* program that fails differs: the ledger does not charge the steps it took
|
|
36
|
+
* since the budget was last checked.
|
|
37
|
+
*
|
|
38
|
+
* Fails only when the inputs are malformed or unsupported. A program that fails
|
|
39
|
+
* is an [`EvalProgramResult`] that is not `ok`.
|
|
40
|
+
*/
|
|
41
|
+
export function eval_program_raw(
|
|
42
|
+
program_flat: Uint8Array,
|
|
43
|
+
args_cbor: Uint8Array[],
|
|
44
|
+
language: number,
|
|
45
|
+
protocol_major_version: number,
|
|
46
|
+
cost_model: BigInt64Array,
|
|
47
|
+
budget_cpu: bigint,
|
|
48
|
+
budget_mem: bigint,
|
|
49
|
+
strict_budget: boolean,
|
|
50
|
+
): EvalProgramResult;
|
|
51
|
+
/**
|
|
52
|
+
* Describes this build of the evaluator as JSON: the uplc crate it was built
|
|
53
|
+
* from, the length of each Plutus version's cost model, and a digest of what a
|
|
54
|
+
* fixed set of programs evaluate to, with their costs, under Plutus V3 and the
|
|
55
|
+
* latest protocol version. Two builds with the same digest agree on those
|
|
56
|
+
* programs; `selfTest` says whether this one gives the expected results.
|
|
57
|
+
*/
|
|
58
|
+
export function uplc_build_info(): string;
|
|
59
|
+
/**
|
|
60
|
+
* The outcome of [`eval_program_raw`].
|
|
61
|
+
*/
|
|
62
|
+
export class EvalProgramResult {
|
|
63
|
+
private constructor();
|
|
64
|
+
free(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Whether the program succeeded: it did not fail and, for Plutus V3, it
|
|
67
|
+
* returned unit.
|
|
68
|
+
*/
|
|
69
|
+
ok: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* The CPU the program used. A program that went over budget is charged
|
|
72
|
+
* what it used up to the point where the machine stopped it.
|
|
73
|
+
*/
|
|
74
|
+
cpu: bigint;
|
|
75
|
+
/**
|
|
76
|
+
* The memory the program used.
|
|
77
|
+
*/
|
|
78
|
+
mem: bigint;
|
|
79
|
+
/**
|
|
80
|
+
* Why the program did not succeed: 0 when it did, 1 when it went over
|
|
81
|
+
* budget, 2 when it failed in any other way and 3 when a Plutus V3 program
|
|
82
|
+
* returned something other than unit.
|
|
83
|
+
*/
|
|
84
|
+
error_kind: number;
|
|
85
|
+
/**
|
|
86
|
+
* The messages the program traced, in order.
|
|
87
|
+
*/
|
|
88
|
+
logs: string[];
|
|
89
|
+
}
|