@crediolabs/policy-synth 0.2.0 → 0.3.1
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 +4 -4
- package/dist/adapters/interpreter/adapter.d.ts +19 -25
- package/dist/adapters/interpreter/adapter.js +54 -487
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.js +1 -4
- package/dist/install/build-add-context-rule.d.ts +3 -19
- package/dist/install/build-add-context-rule.js +3 -98
- package/dist/install/build-install-policy.d.ts +4 -53
- package/dist/install/build-install-policy.js +44 -123
- package/dist/install/index.d.ts +0 -2
- package/dist/install/index.js +0 -7
- package/dist/predicate/decode.d.ts +1 -1
- package/dist/predicate/decode.js +2 -70
- package/dist/predicate/encode.js +45 -229
- package/dist/predicate/from-json.js +1 -42
- package/dist/record/decode.js +3 -8
- package/dist/record/freshness.d.ts +17 -11
- package/dist/record/freshness.js +28 -18
- package/dist/review-card/builder.d.ts +4 -3
- package/dist/review-card/builder.js +18 -162
- package/dist/review-card/cross-check.js +2 -105
- package/dist/review-card/render-leaf.d.ts +4 -0
- package/dist/review-card/render-leaf.js +47 -0
- package/dist/run/index.d.ts +36 -139
- package/dist/run/index.js +125 -437
- package/dist/run/schemas.d.ts +168 -1929
- package/dist/run/schemas.js +40 -269
- package/dist/{synth → simulate}/deny-cases.d.ts +4 -8
- package/dist/simulate/deny-cases.js +282 -0
- package/dist/simulate/evaluate.d.ts +18 -0
- package/dist/simulate/evaluate.js +271 -0
- package/dist/simulate/index.d.ts +4 -0
- package/dist/simulate/index.js +8 -0
- package/dist/synth/compose-from-recording.d.ts +24 -51
- package/dist/synth/compose-from-recording.js +120 -282
- package/dist/synth/index.d.ts +0 -5
- package/dist/synth/index.js +0 -5
- package/dist/synth/synthesize-from-recording.d.ts +1 -29
- package/dist/synth/synthesize-from-recording.js +41 -356
- package/dist/types.d.ts +8 -60
- package/dist/types.js +5 -2
- package/dist-cjs/adapters/interpreter/adapter.d.ts +19 -25
- package/dist-cjs/adapters/interpreter/adapter.js +56 -489
- package/dist-cjs/errors.d.ts +1 -1
- package/dist-cjs/index.d.ts +1 -4
- package/dist-cjs/index.js +1 -4
- package/dist-cjs/install/build-add-context-rule.d.ts +3 -19
- package/dist-cjs/install/build-add-context-rule.js +1 -97
- package/dist-cjs/install/build-install-policy.d.ts +4 -53
- package/dist-cjs/install/build-install-policy.js +44 -122
- package/dist-cjs/install/index.d.ts +0 -2
- package/dist-cjs/install/index.js +2 -23
- package/dist-cjs/predicate/decode.d.ts +1 -1
- package/dist-cjs/predicate/decode.js +2 -70
- package/dist-cjs/predicate/encode.js +45 -229
- package/dist-cjs/predicate/from-json.js +1 -42
- package/dist-cjs/record/decode.js +3 -8
- package/dist-cjs/record/freshness.d.ts +17 -11
- package/dist-cjs/record/freshness.js +28 -18
- package/dist-cjs/review-card/builder.d.ts +4 -3
- package/dist-cjs/review-card/builder.js +23 -167
- package/dist-cjs/review-card/cross-check.js +7 -110
- package/dist-cjs/review-card/render-leaf.d.ts +4 -0
- package/dist-cjs/review-card/render-leaf.js +52 -0
- package/dist-cjs/run/index.d.ts +36 -139
- package/dist-cjs/run/index.js +125 -444
- package/dist-cjs/run/schemas.d.ts +168 -1929
- package/dist-cjs/run/schemas.js +41 -270
- package/dist-cjs/{synth → simulate}/deny-cases.d.ts +4 -8
- package/dist-cjs/simulate/deny-cases.js +286 -0
- package/dist-cjs/simulate/evaluate.d.ts +18 -0
- package/dist-cjs/simulate/evaluate.js +274 -0
- package/dist-cjs/simulate/index.d.ts +4 -0
- package/dist-cjs/simulate/index.js +13 -0
- package/dist-cjs/synth/compose-from-recording.d.ts +24 -51
- package/dist-cjs/synth/compose-from-recording.js +120 -282
- package/dist-cjs/synth/index.d.ts +0 -5
- package/dist-cjs/synth/index.js +1 -11
- package/dist-cjs/synth/synthesize-from-recording.d.ts +1 -29
- package/dist-cjs/synth/synthesize-from-recording.js +39 -354
- package/dist-cjs/types.d.ts +8 -60
- package/dist-cjs/types.js +6 -3
- package/package.json +5 -5
- package/src/adapters/interpreter/adapter.ts +76 -572
- package/src/errors.ts +0 -19
- package/src/index.ts +1 -4
- package/src/install/build-add-context-rule.ts +5 -139
- package/src/install/build-install-policy.ts +93 -214
- package/src/install/index.ts +0 -34
- package/src/predicate/decode.ts +2 -70
- package/src/predicate/encode.ts +49 -261
- package/src/predicate/from-json.ts +1 -43
- package/src/record/decode.ts +3 -8
- package/src/record/freshness.ts +29 -18
- package/src/review-card/builder.ts +19 -168
- package/src/review-card/cross-check.ts +3 -105
- package/src/review-card/render-leaf.ts +48 -0
- package/src/run/index.ts +144 -572
- package/src/run/schemas.ts +42 -291
- package/src/simulate/deny-cases.ts +334 -0
- package/src/simulate/evaluate.ts +284 -0
- package/src/simulate/index.ts +11 -0
- package/src/synth/compose-from-recording.ts +148 -347
- package/src/synth/index.ts +0 -13
- package/src/synth/synthesize-from-recording.ts +43 -456
- package/src/types.ts +13 -49
- package/dist/adapters/interpreter/index.d.ts +0 -1
- package/dist/adapters/interpreter/index.js +0 -2
- package/dist/adapters/oz/adapter.d.ts +0 -20
- package/dist/adapters/oz/adapter.js +0 -295
- package/dist/adapters/oz/index.d.ts +0 -1
- package/dist/adapters/oz/index.js +0 -2
- package/dist/codegen/compile-gate.d.ts +0 -33
- package/dist/codegen/compile-gate.js +0 -124
- package/dist/codegen/index.d.ts +0 -2
- package/dist/codegen/index.js +0 -8
- package/dist/codegen/template.d.ts +0 -18
- package/dist/codegen/template.js +0 -148
- package/dist/install/authority-overlap.d.ts +0 -134
- package/dist/install/authority-overlap.js +0 -0
- package/dist/install/build-install-predicate.d.ts +0 -96
- package/dist/install/build-install-predicate.js +0 -444
- package/dist/install/build-merge-policy.d.ts +0 -70
- package/dist/install/build-merge-policy.js +0 -130
- package/dist/install/plan-merge-policy.d.ts +0 -49
- package/dist/install/plan-merge-policy.js +0 -86
- package/dist/install/read-account-rules.d.ts +0 -100
- package/dist/install/read-account-rules.js +0 -283
- package/dist/ir/index.d.ts +0 -1
- package/dist/ir/index.js +0 -2
- package/dist/ir/types.d.ts +0 -140
- package/dist/ir/types.js +0 -11
- package/dist/mandate/index.d.ts +0 -2
- package/dist/mandate/index.js +0 -2
- package/dist/mandate/to-ir.d.ts +0 -3
- package/dist/mandate/to-ir.js +0 -60
- package/dist/mandate/types.d.ts +0 -20
- package/dist/mandate/types.js +0 -8
- package/dist/seams/index.d.ts +0 -1
- package/dist/seams/index.js +0 -2
- package/dist/seams/types.d.ts +0 -66
- package/dist/seams/types.js +0 -11
- package/dist/synth/deny-cases.js +0 -562
- package/dist/synth/evaluate.d.ts +0 -39
- package/dist/synth/evaluate.js +0 -551
- package/dist/synth/harness.d.ts +0 -28
- package/dist/synth/harness.js +0 -47
- package/dist/synth/minimize.d.ts +0 -4
- package/dist/synth/minimize.js +0 -38
- package/dist/synth/permit-context.d.ts +0 -15
- package/dist/synth/permit-context.js +0 -116
- package/dist/synth/predicate-literals.d.ts +0 -5
- package/dist/synth/predicate-literals.js +0 -25
- package/dist/synth/synthesize-from-mandate.d.ts +0 -20
- package/dist/synth/synthesize-from-mandate.js +0 -59
- package/dist/verify/envelope.d.ts +0 -15
- package/dist/verify/envelope.js +0 -22
- package/dist/verify/index.d.ts +0 -3
- package/dist/verify/index.js +0 -3
- package/dist/verify/simulate.d.ts +0 -31
- package/dist/verify/simulate.js +0 -258
- package/dist/verify/verify.d.ts +0 -21
- package/dist/verify/verify.js +0 -189
- package/dist-cjs/adapters/interpreter/index.d.ts +0 -1
- package/dist-cjs/adapters/interpreter/index.js +0 -8
- package/dist-cjs/adapters/oz/adapter.d.ts +0 -20
- package/dist-cjs/adapters/oz/adapter.js +0 -300
- package/dist-cjs/adapters/oz/index.d.ts +0 -1
- package/dist-cjs/adapters/oz/index.js +0 -8
- package/dist-cjs/codegen/compile-gate.d.ts +0 -33
- package/dist-cjs/codegen/compile-gate.js +0 -128
- package/dist-cjs/codegen/index.d.ts +0 -2
- package/dist-cjs/codegen/index.js +0 -14
- package/dist-cjs/codegen/template.d.ts +0 -18
- package/dist-cjs/codegen/template.js +0 -151
- package/dist-cjs/install/authority-overlap.d.ts +0 -134
- package/dist-cjs/install/authority-overlap.js +0 -0
- package/dist-cjs/install/build-install-predicate.d.ts +0 -96
- package/dist-cjs/install/build-install-predicate.js +0 -479
- package/dist-cjs/install/build-merge-policy.d.ts +0 -70
- package/dist-cjs/install/build-merge-policy.js +0 -134
- package/dist-cjs/install/plan-merge-policy.d.ts +0 -49
- package/dist-cjs/install/plan-merge-policy.js +0 -90
- package/dist-cjs/install/read-account-rules.d.ts +0 -100
- package/dist-cjs/install/read-account-rules.js +0 -296
- package/dist-cjs/ir/index.d.ts +0 -1
- package/dist-cjs/ir/index.js +0 -3
- package/dist-cjs/ir/types.d.ts +0 -140
- package/dist-cjs/ir/types.js +0 -12
- package/dist-cjs/mandate/index.d.ts +0 -2
- package/dist-cjs/mandate/index.js +0 -6
- package/dist-cjs/mandate/to-ir.d.ts +0 -3
- package/dist-cjs/mandate/to-ir.js +0 -63
- package/dist-cjs/mandate/types.d.ts +0 -20
- package/dist-cjs/mandate/types.js +0 -9
- package/dist-cjs/seams/index.d.ts +0 -1
- package/dist-cjs/seams/index.js +0 -3
- package/dist-cjs/seams/types.d.ts +0 -66
- package/dist-cjs/seams/types.js +0 -12
- package/dist-cjs/synth/deny-cases.js +0 -568
- package/dist-cjs/synth/evaluate.d.ts +0 -39
- package/dist-cjs/synth/evaluate.js +0 -554
- package/dist-cjs/synth/harness.d.ts +0 -28
- package/dist-cjs/synth/harness.js +0 -50
- package/dist-cjs/synth/minimize.d.ts +0 -4
- package/dist-cjs/synth/minimize.js +0 -41
- package/dist-cjs/synth/permit-context.d.ts +0 -15
- package/dist-cjs/synth/permit-context.js +0 -119
- package/dist-cjs/synth/predicate-literals.d.ts +0 -5
- package/dist-cjs/synth/predicate-literals.js +0 -28
- package/dist-cjs/synth/synthesize-from-mandate.d.ts +0 -20
- package/dist-cjs/synth/synthesize-from-mandate.js +0 -62
- package/dist-cjs/verify/envelope.d.ts +0 -15
- package/dist-cjs/verify/envelope.js +0 -23
- package/dist-cjs/verify/index.d.ts +0 -3
- package/dist-cjs/verify/index.js +0 -8
- package/dist-cjs/verify/simulate.d.ts +0 -31
- package/dist-cjs/verify/simulate.js +0 -261
- package/dist-cjs/verify/verify.d.ts +0 -21
- package/dist-cjs/verify/verify.js +0 -192
- package/src/adapters/interpreter/index.ts +0 -8
- package/src/adapters/oz/adapter.ts +0 -376
- package/src/adapters/oz/index.ts +0 -9
- package/src/codegen/compile-gate.ts +0 -167
- package/src/codegen/index.ts +0 -17
- package/src/codegen/template.ts +0 -165
- package/src/install/authority-overlap.ts +0 -0
- package/src/install/build-merge-policy.ts +0 -219
- package/src/install/plan-merge-policy.ts +0 -133
- package/src/install/read-account-rules.ts +0 -376
- package/src/ir/index.ts +0 -13
- package/src/ir/types.ts +0 -132
- package/src/mandate/index.ts +0 -4
- package/src/mandate/to-ir.ts +0 -71
- package/src/mandate/types.ts +0 -21
- package/src/seams/index.ts +0 -11
- package/src/seams/types.ts +0 -81
- package/src/synth/deny-cases.ts +0 -663
- package/src/synth/evaluate.ts +0 -613
- package/src/synth/harness.ts +0 -68
- package/src/synth/minimize.ts +0 -48
- package/src/synth/permit-context.ts +0 -136
- package/src/synth/predicate-literals.ts +0 -27
- package/src/synth/synthesize-from-mandate.ts +0 -82
- package/src/verify/envelope.ts +0 -28
- package/src/verify/index.ts +0 -5
- package/src/verify/simulate.ts +0 -311
- package/src/verify/verify.ts +0 -243
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { PredicateNode, RecordedTransaction } from '../types.ts';
|
|
2
|
-
import type { EvalContext } from './evaluate.ts';
|
|
3
|
-
export interface PermitContextResponses {
|
|
4
|
-
windowSeconds: number;
|
|
5
|
-
invocationLimit?: number;
|
|
6
|
-
limitAmount?: string;
|
|
7
|
-
validUntilLedger: number;
|
|
8
|
-
oraclePriceBound?: Array<{
|
|
9
|
-
asset: string;
|
|
10
|
-
operator: string;
|
|
11
|
-
value: string;
|
|
12
|
-
decimals: number;
|
|
13
|
-
}>;
|
|
14
|
-
}
|
|
15
|
-
export declare function buildPermitContext(tx: RecordedTransaction, responses: PermitContextResponses, predicate: PredicateNode): EvalContext;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// src/synth/permit-context.ts - build the EvalContext that represents the
|
|
3
|
-
// recorded call being replayed.
|
|
4
|
-
//
|
|
5
|
-
// Extracted from the over-permissiveness harness so the same construction
|
|
6
|
-
// feeds both the in-process battery and the on-chain replay
|
|
7
|
-
// (scripts/verify-mutations-testnet.ts). Two callers building this
|
|
8
|
-
// separately would be two chances to disagree about what "the recorded
|
|
9
|
-
// call" means, which is the one thing both must share.
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.buildPermitContext = buildPermitContext;
|
|
12
|
-
const deny_cases_ts_1 = require("./deny-cases.js");
|
|
13
|
-
function buildPermitContext(tx, responses, predicate) {
|
|
14
|
-
const amountByToken = {};
|
|
15
|
-
const totals = new Map();
|
|
16
|
-
for (const m of tx.tokenMovements) {
|
|
17
|
-
const current = totals.get(m.token) ?? 0n;
|
|
18
|
-
totals.set(m.token, current + BigInt(m.amount));
|
|
19
|
-
}
|
|
20
|
-
for (const [token, total] of totals) {
|
|
21
|
-
amountByToken[token] = total.toString();
|
|
22
|
-
}
|
|
23
|
-
const topLevel = tx.invocations[0];
|
|
24
|
-
const scopeContract = topLevel?.contract ?? '';
|
|
25
|
-
const oraclePriceByAsset = {};
|
|
26
|
-
visitOracleLeaves(predicate, (asset, op, bound) => {
|
|
27
|
-
let price;
|
|
28
|
-
switch (op) {
|
|
29
|
-
case 'lt':
|
|
30
|
-
price = bound - 1n;
|
|
31
|
-
break;
|
|
32
|
-
case 'gt':
|
|
33
|
-
price = bound + 1n;
|
|
34
|
-
break;
|
|
35
|
-
default:
|
|
36
|
-
price = bound;
|
|
37
|
-
}
|
|
38
|
-
if (price < 0n)
|
|
39
|
-
price = 0n;
|
|
40
|
-
oraclePriceByAsset[asset] = { price: price.toString(), timestampSeconds: tx.fetchedAt };
|
|
41
|
-
});
|
|
42
|
-
const ctx = {
|
|
43
|
-
contract: scopeContract,
|
|
44
|
-
fn: topLevel?.fn ?? '',
|
|
45
|
-
args: (topLevel?.args ?? []).map(deny_cases_ts_1.cloneScVal),
|
|
46
|
-
atLedger: tx.ledgerSequence,
|
|
47
|
-
nowSeconds: tx.fetchedAt,
|
|
48
|
-
amountByToken,
|
|
49
|
-
windowSpentByToken: {},
|
|
50
|
-
invocationCountByWindow: {},
|
|
51
|
-
oraclePriceByAsset,
|
|
52
|
-
};
|
|
53
|
-
if (responses.validUntilLedger !== undefined) {
|
|
54
|
-
ctx.validUntilLedger = responses.validUntilLedger;
|
|
55
|
-
}
|
|
56
|
-
return ctx;
|
|
57
|
-
}
|
|
58
|
-
function visitOracleLeaves(node, visit) {
|
|
59
|
-
switch (node.op) {
|
|
60
|
-
case 'and':
|
|
61
|
-
case 'or':
|
|
62
|
-
for (const child of node.children)
|
|
63
|
-
visitOracleLeaves(child, visit);
|
|
64
|
-
return;
|
|
65
|
-
case 'not':
|
|
66
|
-
visitOracleLeaves(node.child, visit);
|
|
67
|
-
return;
|
|
68
|
-
case 'eq':
|
|
69
|
-
case 'lt':
|
|
70
|
-
case 'lte':
|
|
71
|
-
case 'gt':
|
|
72
|
-
case 'gte': {
|
|
73
|
-
const leftIsOracle = node.left.kind === 'oracle_price';
|
|
74
|
-
const rightIsOracle = node.right.kind === 'oracle_price';
|
|
75
|
-
let asset;
|
|
76
|
-
let literal;
|
|
77
|
-
if (leftIsOracle) {
|
|
78
|
-
asset = node.left.kind === 'oracle_price' ? node.left.asset : undefined;
|
|
79
|
-
literal = oracleThresholdNormalised(node.right);
|
|
80
|
-
}
|
|
81
|
-
else if (rightIsOracle) {
|
|
82
|
-
asset = node.right.kind === 'oracle_price' ? node.right.asset : undefined;
|
|
83
|
-
literal = oracleThresholdNormalised(node.left);
|
|
84
|
-
}
|
|
85
|
-
if (asset !== undefined && literal !== undefined) {
|
|
86
|
-
visit(asset, node.op, literal);
|
|
87
|
-
}
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
case 'in':
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/** Oracle prices normalise to 9 decimals; mirrors NORMALISED_DECIMALS in
|
|
95
|
-
* oracle.rs. */
|
|
96
|
-
const NORMALISED_DECIMALS = 9n;
|
|
97
|
-
/** A threshold restated on the normalised basis, so a derived permit price is
|
|
98
|
-
* comparable to it. Thresholds carry their own basis, so the conversion has
|
|
99
|
-
* to happen here - reading the digits raw would build a context off by a
|
|
100
|
-
* factor of 10^(decimals-9). Returns undefined for any other leaf. */
|
|
101
|
-
function oracleThresholdNormalised(leaf) {
|
|
102
|
-
if (leaf.kind !== 'oracle_threshold')
|
|
103
|
-
return undefined;
|
|
104
|
-
let value;
|
|
105
|
-
try {
|
|
106
|
-
value = BigInt(leaf.value);
|
|
107
|
-
}
|
|
108
|
-
catch {
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
111
|
-
const decimals = BigInt(leaf.decimals);
|
|
112
|
-
if (decimals <= NORMALISED_DECIMALS) {
|
|
113
|
-
return value * 10n ** (NORMALISED_DECIMALS - decimals);
|
|
114
|
-
}
|
|
115
|
-
// Floor: a finer-grained threshold has no exact 9-dp representation. The
|
|
116
|
-
// caller only needs a price that lands on the right side of the bound, and
|
|
117
|
-
// it offsets by one from here.
|
|
118
|
-
return value / 10n ** (decimals - NORMALISED_DECIMALS);
|
|
119
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { PredicateLeaf } from '../types.ts';
|
|
2
|
-
/** BigInt value of a numeric-integer literal leaf (`literal_i128` / `literal_u64`
|
|
3
|
-
* / `literal_u32`), or null for a non-numeric literal (address / symbol / bytes
|
|
4
|
-
* / vec). Callers fail closed on null. */
|
|
5
|
-
export declare function literalNumericBigInt(leaf: PredicateLeaf): bigint | null;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// src/synth/predicate-literals.ts - read scalar values out of predicate literal leaves.
|
|
3
|
-
//
|
|
4
|
-
// Small shared helpers for interpreting a `PredicateLeaf` literal. Kept out of
|
|
5
|
-
// `evaluate.ts` so the evaluator stays focused on the deny-order semantics; the
|
|
6
|
-
// deny-case generator uses the same reader so both sides agree on what a numeric
|
|
7
|
-
// literal means.
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.literalNumericBigInt = literalNumericBigInt;
|
|
10
|
-
/** BigInt value of a numeric-integer literal leaf (`literal_i128` / `literal_u64`
|
|
11
|
-
* / `literal_u32`), or null for a non-numeric literal (address / symbol / bytes
|
|
12
|
-
* / vec). Callers fail closed on null. */
|
|
13
|
-
function literalNumericBigInt(leaf) {
|
|
14
|
-
switch (leaf.kind) {
|
|
15
|
-
case 'literal_i128':
|
|
16
|
-
case 'literal_u64':
|
|
17
|
-
try {
|
|
18
|
-
return BigInt(leaf.value);
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
case 'literal_u32':
|
|
24
|
-
return BigInt(leaf.value);
|
|
25
|
-
default:
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { OzAdapterConfig } from '../adapters/oz/adapter.ts';
|
|
2
|
-
import type { ToolResponse } from '../errors.ts';
|
|
3
|
-
import type { MandateSpec } from '../mandate/types.ts';
|
|
4
|
-
import type { PredicateNode, ProposedPolicy } from '../types.ts';
|
|
5
|
-
import type { SimulationResult } from '../verify/envelope.ts';
|
|
6
|
-
export declare function synthesizeFromMandate(spec: MandateSpec, ozConfig: OzAdapterConfig,
|
|
7
|
-
/** --explain opt-in. When true, the success envelope carries the
|
|
8
|
-
* in-memory predicate tree (always null for the mandate path - the
|
|
9
|
-
* declarative MandateSpec lowers to OZ built-ins, not to an
|
|
10
|
-
* interpreter predicate) + a minimal honest SimulationResult. The
|
|
11
|
-
* flag is ADDITIVE: the existing ProposedPolicy fields are never
|
|
12
|
-
* altered. */
|
|
13
|
-
opts?: {
|
|
14
|
-
explain?: true;
|
|
15
|
-
}): ToolResponse<ProposedPolicy> & {
|
|
16
|
-
explain?: {
|
|
17
|
-
predicateTree: PredicateNode | null;
|
|
18
|
-
simulation: SimulationResult;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// src/synth/synthesize-from-mandate.ts - the deterministic Mandate front-end.
|
|
3
|
-
//
|
|
4
|
-
// synthesizeFromMandate is the clean end-to-end demo path: a declarative
|
|
5
|
-
// MandateSpec is lowered deterministically to a PolicyIR and compiled by the OZ
|
|
6
|
-
// adapter to a ProposedPolicy. No decoding, no inference, so parseConfidence is
|
|
7
|
-
// the full/not-applicable value. Constructs the OZ built-in primitives cannot
|
|
8
|
-
// express (compile's `uncovered`) are surfaced in `ProposedPolicy.warnings`
|
|
9
|
-
// rather than failing the call - the covered primitives still install; the
|
|
10
|
-
// uncovered ones are reported.
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.synthesizeFromMandate = synthesizeFromMandate;
|
|
13
|
-
const adapter_ts_1 = require("../adapters/oz/adapter.js");
|
|
14
|
-
const to_ir_ts_1 = require("../mandate/to-ir.js");
|
|
15
|
-
const UNCOVERED_PREFIX = 'Not covered by OZ built-in primitives: ';
|
|
16
|
-
function synthesizeFromMandate(spec, ozConfig,
|
|
17
|
-
/** --explain opt-in. When true, the success envelope carries the
|
|
18
|
-
* in-memory predicate tree (always null for the mandate path - the
|
|
19
|
-
* declarative MandateSpec lowers to OZ built-ins, not to an
|
|
20
|
-
* interpreter predicate) + a minimal honest SimulationResult. The
|
|
21
|
-
* flag is ADDITIVE: the existing ProposedPolicy fields are never
|
|
22
|
-
* altered. */
|
|
23
|
-
opts) {
|
|
24
|
-
const ir = (0, to_ir_ts_1.mandateToPolicyIR)(spec);
|
|
25
|
-
const adapter = (0, adapter_ts_1.createOzAdapter)(ozConfig);
|
|
26
|
-
const result = adapter.compile(ir);
|
|
27
|
-
if (!result.proposed) {
|
|
28
|
-
return {
|
|
29
|
-
ok: false,
|
|
30
|
-
error: {
|
|
31
|
-
code: 'SYNTHESIS_ERROR',
|
|
32
|
-
message: `mandate lowered to no installable OZ policy: ${result.uncovered.join('; ')}`,
|
|
33
|
-
severity: 'error',
|
|
34
|
-
retryable: false,
|
|
35
|
-
details: { uncovered: result.uncovered },
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
const proposed = {
|
|
40
|
-
...result.proposed,
|
|
41
|
-
warnings: result.uncovered.map((u) => `${UNCOVERED_PREFIX}${u}`),
|
|
42
|
-
};
|
|
43
|
-
// Same --explain envelope pattern as the recording path. The mandate path
|
|
44
|
-
// never produces an interpreter predicate, so predicateTree is null and
|
|
45
|
-
// the simulation is a minimal honest deny (no self-verify was performed).
|
|
46
|
-
const envelope = { ok: true, data: proposed };
|
|
47
|
-
if (opts?.explain) {
|
|
48
|
-
envelope.explain = {
|
|
49
|
-
predicateTree: null,
|
|
50
|
-
simulation: {
|
|
51
|
-
permit: {
|
|
52
|
-
tx: 'deny',
|
|
53
|
-
reason: 'No self-verification was performed (mandate path is OZ-only)',
|
|
54
|
-
},
|
|
55
|
-
evaluatedCases: [],
|
|
56
|
-
backend: 'ts-model',
|
|
57
|
-
simulatorVersion: 'not-run',
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
return envelope;
|
|
62
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type SimulationResult = {
|
|
2
|
-
permit: {
|
|
3
|
-
tx: 'permit';
|
|
4
|
-
} | {
|
|
5
|
-
tx: 'deny';
|
|
6
|
-
reason: string;
|
|
7
|
-
};
|
|
8
|
-
evaluatedCases: Array<{
|
|
9
|
-
dimension: string;
|
|
10
|
-
outcome: 'permit' | 'deny';
|
|
11
|
-
reason: string;
|
|
12
|
-
}>;
|
|
13
|
-
backend: 'interpreter-v1' | 'ts-model';
|
|
14
|
-
simulatorVersion: string;
|
|
15
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// src/verify/envelope.ts - the post-simulation result envelope used by
|
|
3
|
-
// review-card rendering and verification.
|
|
4
|
-
//
|
|
5
|
-
// `SimulationResult` is the structured verdict a `simulate_policy` run
|
|
6
|
-
// produces; the review-card builder reads it as one of its inputs (so the
|
|
7
|
-
// rendered card can quote the backend that evaluated the policy) and the
|
|
8
|
-
// verification pipeline reads `permit` + `evaluatedCases` to confirm every
|
|
9
|
-
// generated deny case really did deny.
|
|
10
|
-
//
|
|
11
|
-
// This envelope is intentionally separate from the CustodyAdapter
|
|
12
|
-
// `SimulationResult` in `src/seams/types.ts` (which is the dry-run stub
|
|
13
|
-
// returned by `adapter.simulate(ir, permitTx)`); the seam result is the
|
|
14
|
-
// adapter contract, this envelope is the post-simulation record consumed by
|
|
15
|
-
// downstream rendering + verification.
|
|
16
|
-
//
|
|
17
|
-
// Fields:
|
|
18
|
-
// - `permit` is the single verdict for the candidate recorded tx.
|
|
19
|
-
// - `evaluatedCases` is the deny-case battery outcome (every dimension
|
|
20
|
-
// must report `deny` when the policy is minimal).
|
|
21
|
-
// - `backend` is the actual evaluator that produced the verdict.
|
|
22
|
-
// - `simulatorVersion` lets the reviewer / audit log distinguish runs.
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist-cjs/verify/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// src/verify/index.ts - re-export the simulation / verification surface.
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.verifyPolicy = exports.simulatePolicy = void 0;
|
|
5
|
-
var simulate_ts_1 = require("./simulate.js");
|
|
6
|
-
Object.defineProperty(exports, "simulatePolicy", { enumerable: true, get: function () { return simulate_ts_1.simulatePolicy; } });
|
|
7
|
-
var verify_ts_1 = require("./verify.js");
|
|
8
|
-
Object.defineProperty(exports, "verifyPolicy", { enumerable: true, get: function () { return verify_ts_1.verifyPolicy; } });
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { ToolResponse } from '../errors.ts';
|
|
2
|
-
import type { PredicateNode, RecordedTransaction } from '../types.ts';
|
|
3
|
-
import type { SimulationResult } from './envelope.ts';
|
|
4
|
-
/** Options for `simulatePolicy`. `validUntilLedger` is propagated onto the
|
|
5
|
-
* permit EvalContext so the simulator exercises the expiry gate; absent ->
|
|
6
|
-
* no expiry check (mirrors the orchestrator's "no `validUntilLedger`
|
|
7
|
-
* supplied" path). `oraclePricesByAsset` is the test fixture the simulator
|
|
8
|
-
* uses to satisfy `oracle_price` leaves so the permit call evaluates under
|
|
9
|
-
* the bound; absent -> derive satisfying prices from the predicate itself
|
|
10
|
-
* (the orchestrator's oracle-satisfying-price logic). */
|
|
11
|
-
export interface SimulateOptions {
|
|
12
|
-
validUntilLedger?: number;
|
|
13
|
-
/** Pre-populated oracle-price entries keyed by asset address. The fixture
|
|
14
|
-
* must satisfy every `oracle_price` leaf in the predicate; absent or
|
|
15
|
-
* unsatisfying entries cause `SIMULATION_ERROR`. */
|
|
16
|
-
oraclePricesByAsset?: Record<string, {
|
|
17
|
-
price: string;
|
|
18
|
-
timestampSeconds: number;
|
|
19
|
-
} | {
|
|
20
|
-
error: 'stale' | 'missing' | 'deviation' | 'paused' | 'decimals' | 'fingerprint';
|
|
21
|
-
}>;
|
|
22
|
-
}
|
|
23
|
-
/** Replay a recorded transaction against a proposed predicate and emit the
|
|
24
|
-
* `SimulationResult` envelope. The simulator returns the SAME permit
|
|
25
|
-
* verdict `runHarness` expects: the intended recorded call must permit; every
|
|
26
|
-
* generated deny dimension must deny. A runtime evaluation failure
|
|
27
|
-
* (malformed input, missing oracle fixture, etc.) returns a `SIMULATION_ERROR`
|
|
28
|
-
* `ToolError` - NOT a deny verdict, NOT `VERIFICATION_FAILED`. The boundary
|
|
29
|
-
* is pinned: minimality is a verify-time concern, runtime evaluation is a
|
|
30
|
-
* simulate-time concern. */
|
|
31
|
-
export declare function simulatePolicy(predicate: PredicateNode | null, permitTx: RecordedTransaction, opts?: SimulateOptions): ToolResponse<SimulationResult>;
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// src/verify/simulate.ts - the post-simulation verdict for `simulate_policy`.
|
|
3
|
-
//
|
|
4
|
-
// `simulatePolicy` replays a recorded transaction against a proposed
|
|
5
|
-
// `PredicateNode` and emits the `SimulationResult` envelope the review-card
|
|
6
|
-
// builder + the verification pipeline consume.
|
|
7
|
-
//
|
|
8
|
-
// Boundary (pinned, must not drift):
|
|
9
|
-
// - `SIMULATION_ERROR` = RUNTIME evaluation failed. Surfaced by
|
|
10
|
-
// `simulatePolicy`. Reasons: malformed `permitTx` input (no top-level
|
|
11
|
-
// invocation to build an EvalContext from), a referenced oracle asset
|
|
12
|
-
// without a satisfying price fixture, or a non-runtime propagation (a
|
|
13
|
-
// throw that is not an oracle error or a controlled deny). A
|
|
14
|
-
// runtime evaluation failure is NOT a policy-minimality problem; the
|
|
15
|
-
// policy may still be minimal. Re-running with a complete fixture MAY
|
|
16
|
-
// succeed.
|
|
17
|
-
// - `VERIFICATION_FAILED` = STATIC minimality check failed. Surfaced
|
|
18
|
-
// by `verifyPolicy`. The minimiser identified a load-bearing-free
|
|
19
|
-
// constraint; the policy is structurally over-broad regardless of how
|
|
20
|
-
// any concrete call evaluates. Re-running with a different fixture
|
|
21
|
-
// will NOT fix it; the policy must be trimmed.
|
|
22
|
-
//
|
|
23
|
-
// Determinism: same `(predicate, permitTx, opts)` -> byte-identical
|
|
24
|
-
// envelope, no clock, no randomness.
|
|
25
|
-
//
|
|
26
|
-
// The permit EvalContext is built locally (mirror of the helper used in
|
|
27
|
-
// `synthesize-from-recording.ts`) so this module does not couple to the
|
|
28
|
-
// orchestrator's private build helpers. The shape is pinned by the test
|
|
29
|
-
// suite to stay in lockstep.
|
|
30
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.simulatePolicy = simulatePolicy;
|
|
32
|
-
const deny_cases_ts_1 = require("../synth/deny-cases.js");
|
|
33
|
-
const evaluate_ts_1 = require("../synth/evaluate.js");
|
|
34
|
-
const types_ts_1 = require("../types.js");
|
|
35
|
-
const SIMULATOR_VERSION = 'ts-model-1.0.0';
|
|
36
|
-
/** Replay a recorded transaction against a proposed predicate and emit the
|
|
37
|
-
* `SimulationResult` envelope. The simulator returns the SAME permit
|
|
38
|
-
* verdict `runHarness` expects: the intended recorded call must permit; every
|
|
39
|
-
* generated deny dimension must deny. A runtime evaluation failure
|
|
40
|
-
* (malformed input, missing oracle fixture, etc.) returns a `SIMULATION_ERROR`
|
|
41
|
-
* `ToolError` - NOT a deny verdict, NOT `VERIFICATION_FAILED`. The boundary
|
|
42
|
-
* is pinned: minimality is a verify-time concern, runtime evaluation is a
|
|
43
|
-
* simulate-time concern. */
|
|
44
|
-
function simulatePolicy(predicate, permitTx, opts = {}) {
|
|
45
|
-
// The permit EvalContext requires a top-level invocation. A recorded tx
|
|
46
|
-
// with no invocations is structurally malformed input - we surface a
|
|
47
|
-
// runtime `SIMULATION_ERROR` rather than fabricating a permit verdict.
|
|
48
|
-
const topLevel = permitTx.invocations[0];
|
|
49
|
-
if (!topLevel) {
|
|
50
|
-
return {
|
|
51
|
-
ok: false,
|
|
52
|
-
error: simulationError('recorded transaction has no top-level invocation to simulate'),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
let permitCtx;
|
|
56
|
-
try {
|
|
57
|
-
permitCtx = buildPermitContext(predicate, permitTx, topLevel, opts);
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
return {
|
|
61
|
-
ok: false,
|
|
62
|
-
error: simulationError(`could not build permit evaluation context: ${e.message}`),
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
// `predicate === null` means the policy is OZ-only (no interpreter
|
|
66
|
-
// predicate). We still emit the envelope so the review card + verifier
|
|
67
|
-
// can consume it: the permit verdict evaluates an always-permit empty
|
|
68
|
-
// tree, and the deny battery is empty (nothing to verify at the
|
|
69
|
-
// interpreter layer).
|
|
70
|
-
const evaluatePredicate = predicate ?? { op: 'and', children: [] };
|
|
71
|
-
const evaluatedCases = [];
|
|
72
|
-
let permitVerdict;
|
|
73
|
-
try {
|
|
74
|
-
permitVerdict = (0, evaluate_ts_1.evaluate)(evaluatePredicate, permitCtx);
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
return {
|
|
78
|
-
ok: false,
|
|
79
|
-
error: simulationError(`permit evaluation threw at runtime: ${e.message}`, e),
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
evaluatedCases.push({
|
|
83
|
-
dimension: 'permit',
|
|
84
|
-
outcome: permitVerdict.permit ? 'permit' : 'deny',
|
|
85
|
-
reason: permitVerdict.permit ? 'matches recorded call' : permitVerdict.reason,
|
|
86
|
-
});
|
|
87
|
-
// The deny battery is generated against the SAME permit context. A
|
|
88
|
-
// runtime evaluation failure on ANY deny case is a `SIMULATION_ERROR` -
|
|
89
|
-
// not a deny verdict (an evaluate-throws is not a deny) and not a
|
|
90
|
-
// minimality problem.
|
|
91
|
-
const cases = (0, deny_cases_ts_1.generateCases)(evaluatePredicate, permitCtx);
|
|
92
|
-
for (const deny of cases.denies) {
|
|
93
|
-
let result;
|
|
94
|
-
try {
|
|
95
|
-
result = (0, evaluate_ts_1.evaluate)(evaluatePredicate, deny.ctx);
|
|
96
|
-
}
|
|
97
|
-
catch (e) {
|
|
98
|
-
return {
|
|
99
|
-
ok: false,
|
|
100
|
-
error: simulationError(`deny case "${deny.dimension}" threw at runtime: ${e.message}`, e),
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
evaluatedCases.push({
|
|
104
|
-
dimension: deny.dimension,
|
|
105
|
-
outcome: result.permit ? 'permit' : 'deny',
|
|
106
|
-
reason: result.permit ? 'no matching deny' : result.reason,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
const envelope = {
|
|
110
|
-
permit: permitVerdict.permit ? { tx: 'permit' } : { tx: 'deny', reason: permitVerdict.reason },
|
|
111
|
-
evaluatedCases,
|
|
112
|
-
backend: 'ts-model',
|
|
113
|
-
simulatorVersion: SIMULATOR_VERSION,
|
|
114
|
-
};
|
|
115
|
-
return { ok: true, data: envelope };
|
|
116
|
-
}
|
|
117
|
-
/** Build the permit `EvalContext` the simulator drives. Mirrors the
|
|
118
|
-
* helper in `synthesize-from-recording.ts` so the simulator sees the same
|
|
119
|
-
* shape the orchestrator's self-verify pipeline sees; we mirror here
|
|
120
|
-
* rather than import to keep `src/verify/` decoupled from the
|
|
121
|
-
* orchestrator's private helpers. The shape is pinned by tests so the
|
|
122
|
-
* two implementations stay in lockstep. */
|
|
123
|
-
function buildPermitContext(predicate, tx, topLevel, opts) {
|
|
124
|
-
const amountByToken = {};
|
|
125
|
-
const totals = new Map();
|
|
126
|
-
for (const m of tx.tokenMovements) {
|
|
127
|
-
const current = totals.get(m.token) ?? 0n;
|
|
128
|
-
totals.set(m.token, current + BigInt(m.amount));
|
|
129
|
-
}
|
|
130
|
-
for (const [token, total] of totals) {
|
|
131
|
-
amountByToken[token] = total.toString();
|
|
132
|
-
}
|
|
133
|
-
// Oracle prices: when the caller supplies a fixture, use it; otherwise
|
|
134
|
-
// derive a satisfying entry per `oracle_price` leaf in the predicate so
|
|
135
|
-
// the permit call permits. Negatives are clamped at 0 (Stellar oracle
|
|
136
|
-
// prices are non-negative).
|
|
137
|
-
const oraclePriceByAsset = {};
|
|
138
|
-
if (opts.oraclePricesByAsset) {
|
|
139
|
-
for (const [asset, entry] of Object.entries(opts.oraclePricesByAsset)) {
|
|
140
|
-
oraclePriceByAsset[asset] = entry;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (predicate !== null) {
|
|
144
|
-
visitOracleLeaves(predicate, (asset, op, bound) => {
|
|
145
|
-
// A caller-supplied fixture entry always wins; we only fill gaps.
|
|
146
|
-
if (oraclePriceByAsset[asset] !== undefined)
|
|
147
|
-
return;
|
|
148
|
-
let price;
|
|
149
|
-
switch (op) {
|
|
150
|
-
case 'lt':
|
|
151
|
-
case 'gt':
|
|
152
|
-
price = op === 'lt' ? bound - 1n : bound + 1n;
|
|
153
|
-
break;
|
|
154
|
-
case 'lte':
|
|
155
|
-
case 'gte':
|
|
156
|
-
case 'eq':
|
|
157
|
-
price = bound;
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
if (price < 0n)
|
|
161
|
-
price = 0n;
|
|
162
|
-
oraclePriceByAsset[asset] = {
|
|
163
|
-
price: price.toString(),
|
|
164
|
-
timestampSeconds: tx.fetchedAt,
|
|
165
|
-
};
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
const ctx = {
|
|
169
|
-
contract: topLevel.contract,
|
|
170
|
-
fn: topLevel.fn,
|
|
171
|
-
args: topLevel.args.map(cloneScVal),
|
|
172
|
-
atLedger: tx.ledgerSequence,
|
|
173
|
-
nowSeconds: tx.fetchedAt,
|
|
174
|
-
amountByToken,
|
|
175
|
-
windowSpentByToken: {},
|
|
176
|
-
invocationCountByWindow: {},
|
|
177
|
-
oraclePriceByAsset,
|
|
178
|
-
};
|
|
179
|
-
if (opts.validUntilLedger !== undefined) {
|
|
180
|
-
ctx.validUntilLedger = opts.validUntilLedger;
|
|
181
|
-
}
|
|
182
|
-
return ctx;
|
|
183
|
-
}
|
|
184
|
-
function cloneScVal(value, depth = 0) {
|
|
185
|
-
// Recursion is bounded by MAX_SCVAL_CLONE_DEPTH so a hand-crafted nested-vec
|
|
186
|
-
// payload cannot RangeError the JS stack during context building. Over-depth
|
|
187
|
-
// throws a ToolError-shaped error that the simulator's existing try/catch
|
|
188
|
-
// converts to a structured `{ok:false, error}` (not a thrown RangeError).
|
|
189
|
-
if (value.type === 'vec') {
|
|
190
|
-
if (depth >= types_ts_1.MAX_SCVAL_CLONE_DEPTH) {
|
|
191
|
-
throw cloneDepthError(value);
|
|
192
|
-
}
|
|
193
|
-
return { type: 'vec', value: value.value.map((v) => cloneScVal(v, depth + 1)) };
|
|
194
|
-
}
|
|
195
|
-
return { ...value };
|
|
196
|
-
}
|
|
197
|
-
function cloneDepthError(value) {
|
|
198
|
-
const err = new Error(`ScVal clone depth exceeds MAX_SCVAL_CLONE_DEPTH (${types_ts_1.MAX_SCVAL_CLONE_DEPTH})`);
|
|
199
|
-
err.code = 'SIMULATION_ERROR';
|
|
200
|
-
err.severity = 'error';
|
|
201
|
-
err.retryable = false;
|
|
202
|
-
err.depthContext = value.type;
|
|
203
|
-
throw err;
|
|
204
|
-
}
|
|
205
|
-
function visitOracleLeaves(node, visit) {
|
|
206
|
-
switch (node.op) {
|
|
207
|
-
case 'and':
|
|
208
|
-
case 'or':
|
|
209
|
-
for (const child of node.children)
|
|
210
|
-
visitOracleLeaves(child, visit);
|
|
211
|
-
return;
|
|
212
|
-
case 'not':
|
|
213
|
-
visitOracleLeaves(node.child, visit);
|
|
214
|
-
return;
|
|
215
|
-
case 'eq':
|
|
216
|
-
case 'lt':
|
|
217
|
-
case 'lte':
|
|
218
|
-
case 'gt':
|
|
219
|
-
case 'gte': {
|
|
220
|
-
const leftLeaf = node.left;
|
|
221
|
-
const rightLeaf = node.right;
|
|
222
|
-
let oracleAsset;
|
|
223
|
-
let literal;
|
|
224
|
-
if (leftLeaf.kind === 'oracle_price') {
|
|
225
|
-
oracleAsset = leftLeaf.asset;
|
|
226
|
-
literal = oracleLiteralFromLeaf(rightLeaf);
|
|
227
|
-
}
|
|
228
|
-
else if (rightLeaf.kind === 'oracle_price') {
|
|
229
|
-
oracleAsset = rightLeaf.asset;
|
|
230
|
-
literal = oracleLiteralFromLeaf(leftLeaf);
|
|
231
|
-
}
|
|
232
|
-
if (oracleAsset === undefined || literal === undefined)
|
|
233
|
-
return;
|
|
234
|
-
visit(oracleAsset, node.op, literal);
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
case 'in':
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
function oracleLiteralFromLeaf(leaf) {
|
|
242
|
-
if (leaf.kind !== 'literal_i128')
|
|
243
|
-
return undefined;
|
|
244
|
-
try {
|
|
245
|
-
return BigInt(leaf.value);
|
|
246
|
-
}
|
|
247
|
-
catch {
|
|
248
|
-
return undefined;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
function simulationError(message, cause) {
|
|
252
|
-
const error = {
|
|
253
|
-
code: 'SIMULATION_ERROR',
|
|
254
|
-
message,
|
|
255
|
-
severity: 'error',
|
|
256
|
-
retryable: false,
|
|
257
|
-
};
|
|
258
|
-
if (cause !== undefined)
|
|
259
|
-
error.details = { cause: String(cause) };
|
|
260
|
-
return error;
|
|
261
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ToolResponse } from '../errors.ts';
|
|
2
|
-
import type { PredicateNode, RecordedTransaction } from '../types.ts';
|
|
3
|
-
/** Options for `verifyPolicy`. Mirrors the orchestrator's permit-context
|
|
4
|
-
* knobs (expiry; oracle fixture) so verify sees the same shape
|
|
5
|
-
* `simulatePolicy` sees. */
|
|
6
|
-
export interface VerifyOptions {
|
|
7
|
-
validUntilLedger?: number;
|
|
8
|
-
oraclePricesByAsset?: Record<string, {
|
|
9
|
-
price: string;
|
|
10
|
-
timestampSeconds: number;
|
|
11
|
-
} | {
|
|
12
|
-
error: 'stale' | 'missing' | 'deviation' | 'paused' | 'decimals' | 'fingerprint';
|
|
13
|
-
}>;
|
|
14
|
-
}
|
|
15
|
-
/** Run the static minimality check on a proposed predicate + recorded tx.
|
|
16
|
-
* Returns `{ ok: true }` when the predicate is minimal (every top-level
|
|
17
|
-
* conjunct carries load) and `VERIFICATION_FAILED` when a conjunct could
|
|
18
|
-
* be dropped without losing a deny-case. The dropped conjuncts are
|
|
19
|
-
* reported in `details.droppedConstraints` so the caller can render a
|
|
20
|
-
* review-card warning. */
|
|
21
|
-
export declare function verifyPolicy(predicate: PredicateNode, permitTx: RecordedTransaction, opts?: VerifyOptions): ToolResponse<true>;
|