@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,16 +1,10 @@
|
|
|
1
1
|
// src/adapters/interpreter/adapter.ts - the interpreter-policy CustodyAdapter.
|
|
2
2
|
//
|
|
3
3
|
// Compiles a PolicyIR to a single interpreter `PolicyDocument` + `PolicyRef`
|
|
4
|
-
// carrying the canonical predicate encoding from `predicate/encode.ts`.
|
|
5
|
-
//
|
|
6
|
-
// IR constructs between them.
|
|
4
|
+
// carrying the canonical predicate encoding from `predicate/encode.ts`. This is
|
|
5
|
+
// the only backend; the compose step lowers every constraint to it.
|
|
7
6
|
//
|
|
8
7
|
// Three fail-closed enforcement gates (per spec):
|
|
9
|
-
// - oracle_price leaves MUST sit directly under the top-level `and`; nesting
|
|
10
|
-
// under `not` / `or` / inside `in` throws ORACLE_LEAF_INVALID_POSITION.
|
|
11
|
-
// - oracleParams overrides may only TIGHTEN vs wasm defaults
|
|
12
|
-
// (maxStalenessSeconds <= 600, maxDeviationBps <= 200); a widening value
|
|
13
|
-
// throws ORACLE_PARAMS_OUT_OF_RANGE at compile time.
|
|
14
8
|
// - an `in` allowlist (or a `compare eq` vs an address, or any value in an
|
|
15
9
|
// `eq_seq`) that targets the smart account's own address throws
|
|
16
10
|
// SCOPE_SELF_CALL.
|
|
@@ -18,27 +12,12 @@
|
|
|
18
12
|
// Anything the adapter genuinely cannot express (EVM calldata / value, unix
|
|
19
13
|
// expiry, etc.) is named in `uncovered` rather than silently dropped.
|
|
20
14
|
import { encodePredicate } from "../../predicate/encode.js";
|
|
15
|
+
import { GRAMMAR_VERSION, } from "../../types.js";
|
|
21
16
|
/** [VERIFY] NOT a real deployed address. The interpreter is a per-network
|
|
22
17
|
* deploy artifact we do not have yet; install is a later phase. */
|
|
23
18
|
export const PLACEHOLDER_INTERPRETER_ADDRESS = 'VERIFY-interpreter-address';
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
export const ORACLE_DEFAULTS = {
|
|
27
|
-
maxStalenessSeconds: 600,
|
|
28
|
-
maxDeviationBps: 200,
|
|
29
|
-
};
|
|
30
|
-
const CAPABILITIES = {
|
|
31
|
-
supportsSpendWindow: true,
|
|
32
|
-
supportsThreshold: false, // thresholds are the OZ adapter's job
|
|
33
|
-
// Expiry is via the context rule's validUntilLedger, not a predicate - the
|
|
34
|
-
// interpreter refuses a `valid_until` leaf at install.
|
|
35
|
-
supportsTimeExpiry: false,
|
|
36
|
-
supportsOraclePrice: true,
|
|
37
|
-
supportsInvocationCount: true,
|
|
38
|
-
supportsGeneralPredicate: true,
|
|
39
|
-
};
|
|
40
|
-
/** Parse confidence for a deterministic (non-decoded) input: full (1.0). A
|
|
41
|
-
* mandate needs no decoding, so the gate is not applicable. */
|
|
19
|
+
/** Parse confidence for a deterministic (non-decoded) input: full (1.0). An
|
|
20
|
+
* input that needs no decoding has nothing for the gate to judge. */
|
|
42
21
|
const FULL_PARSE_CONFIDENCE = {
|
|
43
22
|
overall: 1,
|
|
44
23
|
knownContracts: [],
|
|
@@ -46,53 +25,26 @@ const FULL_PARSE_CONFIDENCE = {
|
|
|
46
25
|
opaqueScVals: [],
|
|
47
26
|
thresholdUsed: 1,
|
|
48
27
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
compile: (ir) => compile(ir, config),
|
|
55
|
-
simulate: () => simulateStub(),
|
|
56
|
-
export: (ir) => canonicalStringify(ir),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
/** Lower a single IR rule to the canonical pre-encoding `PredicateNode`. The
|
|
60
|
-
* orchestrator uses this to wire the self-verify + minimise pipeline: after
|
|
61
|
-
* `compile(ir)` succeeds it re-derives the PredicateNode via this helper to
|
|
62
|
-
* drive `minimize` and `runHarness` on the SAME shape the encoder saw. Pure
|
|
63
|
-
* and deterministic: same `rule + config` -> byte-identical PredicateNode.
|
|
64
|
-
* The `uncovered` list is NOT re-derived - callers needing it must use
|
|
65
|
-
* `compile(ir)`. */
|
|
28
|
+
/** Lower a single rule to the canonical pre-encoding `PredicateNode`. The
|
|
29
|
+
* orchestrator re-derives the PredicateNode through this helper so it holds the
|
|
30
|
+
* SAME shape the encoder saw. Pure and deterministic: same `rule + config` ->
|
|
31
|
+
* byte-identical PredicateNode. The `uncovered` list is NOT re-derived -
|
|
32
|
+
* callers needing it must use `compileInterpreterPolicy(rule, config)`. */
|
|
66
33
|
export function lowerRuleToPredicate(rule, config) {
|
|
67
34
|
return lowerRule(rule, config).predicate;
|
|
68
35
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
assertOracleParamsTighten(config.oracleParams);
|
|
73
|
-
const firstRule = ir.rules[0];
|
|
74
|
-
if (!firstRule) {
|
|
75
|
-
return { covered: false, uncovered: ['empty PolicyIR (no rules to compile)'] };
|
|
76
|
-
}
|
|
77
|
-
if (ir.rules.length > 1) {
|
|
78
|
-
return {
|
|
79
|
-
covered: false,
|
|
80
|
-
uncovered: [
|
|
81
|
-
`multi-rule PolicyIR: ${ir.rules.length - 1} rule(s) beyond the first are not compiled (the interpreter adapter handles one rule per document in this slice)`,
|
|
82
|
-
],
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
const lowered = lowerRule(firstRule, config);
|
|
36
|
+
/** Compile a composed rule to an installable interpreter policy. */
|
|
37
|
+
export function compileInterpreterPolicy(rule, config) {
|
|
38
|
+
const lowered = lowerRule(rule, config);
|
|
86
39
|
if (lowered.uncovered.length > 0) {
|
|
87
40
|
return { covered: false, uncovered: lowered.uncovered };
|
|
88
41
|
}
|
|
89
42
|
const { encodedPredicate, predicateHash } = encodePredicate(lowered.predicate);
|
|
90
43
|
const policyDocument = {
|
|
91
|
-
grammarVersion:
|
|
44
|
+
grammarVersion: GRAMMAR_VERSION,
|
|
92
45
|
installNonce: config.installNonce,
|
|
93
46
|
encodedPredicate,
|
|
94
47
|
predicateHash,
|
|
95
|
-
...(config.oracleParams ? { oracleParams: config.oracleParams } : {}),
|
|
96
48
|
};
|
|
97
49
|
const policyRef = {
|
|
98
50
|
kind: 'interpreter',
|
|
@@ -113,56 +65,18 @@ function lowerRule(rule, config) {
|
|
|
113
65
|
const uncovered = [];
|
|
114
66
|
// scope -> context rule + sibling predicates. contract/method each become
|
|
115
67
|
// their own `eq` leaf and are merged into the top-level `and` alongside the
|
|
116
|
-
// constraints. The top-level MUST be `and`
|
|
117
|
-
// under it (mandatory per the oracle position rule + canonical hash stability).
|
|
68
|
+
// constraints. The top-level MUST be `and` for canonical hash stability.
|
|
118
69
|
const scopeContract = rule.scope.contract;
|
|
119
70
|
const scopeMethod = rule.scope.method;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (rule.roles.length > 0) {
|
|
124
|
-
uncovered.push(`roles [${rule.roles.join(', ')}] dropped (role-to-signer mapping is a later phase; interpreter policies reference addresses, not role names)`);
|
|
125
|
-
}
|
|
126
|
-
if (rule.guard) {
|
|
127
|
-
uncovered.push(`guard: ${describeCondition(rule.guard)} (interpreter adapter currently treats guards as uncovered)`);
|
|
128
|
-
}
|
|
129
|
-
// expiry -> context rule validUntilLedger only. Unix-timestamp expiry is
|
|
130
|
-
// honoured by the interpreter (the `valid_until` selector), but we surface
|
|
131
|
-
// it here as Path-B because the IR contract already says "OZ context rules
|
|
132
|
-
// expire by ledger sequence" and we keep one expiry model for both adapters.
|
|
133
|
-
let validUntilLedger = null;
|
|
134
|
-
if (rule.expiry) {
|
|
135
|
-
if (rule.expiry.validUntilLedger !== undefined) {
|
|
136
|
-
validUntilLedger = rule.expiry.validUntilLedger;
|
|
137
|
-
}
|
|
138
|
-
else if (rule.expiry.validUntilUnixSeconds !== undefined) {
|
|
139
|
-
uncovered.push('time expiry given as a unix timestamp (interpreter adapter currently lowers expiry only via the OZ context-rule validUntilLedger; supply expiry.validUntilLedger)');
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
// approval is the OZ adapter's job (it lowers to simple_threshold /
|
|
143
|
-
// weighted_threshold primitives). Surface it here so a caller that drops it
|
|
144
|
-
// through to the interpreter adapter sees an explicit uncovered entry
|
|
145
|
-
// instead of a silently-dropped M-of-N gate.
|
|
146
|
-
if (rule.approval) {
|
|
147
|
-
uncovered.push(`approval threshold ${rule.approval.threshold} not emitted by the interpreter adapter (thresholds lower to OZ built-in primitives in the OZ adapter)`);
|
|
148
|
-
}
|
|
71
|
+
// expiry -> the context rule's own validUntilLedger. The interpreter has no
|
|
72
|
+
// expiry selector; a policy's lifetime is the OZ context rule's lifetime.
|
|
73
|
+
const validUntilLedger = rule.expiry?.validUntilLedger ?? null;
|
|
149
74
|
// Pre-scan constraints: anything the interpreter adapter cannot express is
|
|
150
75
|
// named in `uncovered` and skipped from the predicate lowering. We surface
|
|
151
76
|
// these BEFORE lowering so the predicate is built from only the
|
|
152
77
|
// expressible subset.
|
|
153
|
-
const expressibleConstraints = [];
|
|
154
|
-
for (const c of rule.constraints) {
|
|
155
|
-
const unsupp = unsupportedConstruct(c);
|
|
156
|
-
if (unsupp !== null) {
|
|
157
|
-
uncovered.push(unsupp);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
expressibleConstraints.push(c);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
78
|
// Build the top-level `and` of scope + expressible constraints. The
|
|
164
|
-
// top-level MUST be `and`
|
|
165
|
-
// position rule is enforced inside `lowerCondition`.
|
|
79
|
+
// top-level MUST be `and` for canonical hash stability.
|
|
166
80
|
const topChildren = [];
|
|
167
81
|
if (scopeContract !== undefined) {
|
|
168
82
|
topChildren.push({
|
|
@@ -178,14 +92,23 @@ function lowerRule(rule, config) {
|
|
|
178
92
|
right: { kind: 'literal_symbol', value: scopeMethod },
|
|
179
93
|
});
|
|
180
94
|
}
|
|
181
|
-
|
|
182
|
-
|
|
95
|
+
topChildren.push(...rule.constraints);
|
|
96
|
+
// One walk over the whole tree rejects any literal naming the smart account
|
|
97
|
+
// itself. Previously three separate call sites did this per construct, which
|
|
98
|
+
// meant a new construct could be added without one.
|
|
99
|
+
for (const node of topChildren) {
|
|
100
|
+
assertNoSelfCall(node, config);
|
|
183
101
|
}
|
|
184
102
|
const predicate = topChildren.length === 1 && topChildren[0] !== undefined
|
|
185
103
|
? topChildren[0]
|
|
186
104
|
: { op: 'and', children: topChildren };
|
|
105
|
+
// Scope the context rule to the contract when the rule names one, matching
|
|
106
|
+
// what OZ's CallContract scoping did. A `default` rule would route EVERY
|
|
107
|
+
// call through this policy instead of only calls to the scoped contract.
|
|
187
108
|
const contextRule = {
|
|
188
|
-
contextRuleType:
|
|
109
|
+
contextRuleType: scopeContract !== undefined
|
|
110
|
+
? { kind: 'call_contract', contract: scopeContract }
|
|
111
|
+
: { kind: 'default' },
|
|
189
112
|
name: 'interpreter',
|
|
190
113
|
validUntilLedger,
|
|
191
114
|
signers: [],
|
|
@@ -193,392 +116,36 @@ function lowerRule(rule, config) {
|
|
|
193
116
|
};
|
|
194
117
|
return { predicate, contextRule, uncovered };
|
|
195
118
|
}
|
|
196
|
-
/**
|
|
197
|
-
*
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
// is BOTH misplaced-oracle and unsourceable would be silently dropped
|
|
208
|
-
// instead of rejected.
|
|
209
|
-
assertNoOracleDescendants(cond);
|
|
210
|
-
return (unsourceableSelector(cond.selector) ??
|
|
211
|
-
(cond.selector.kind === 'calldata' || cond.selector.kind === 'value'
|
|
212
|
-
? `EVM \`${cond.selector.kind}\` selector on allowlist (predicate DSL)`
|
|
213
|
-
: null));
|
|
214
|
-
case 'eq_seq':
|
|
215
|
-
return (unsourceableSelector(cond.selector) ??
|
|
216
|
-
(cond.selector.kind === 'calldata' || cond.selector.kind === 'value'
|
|
217
|
-
? `EVM \`${cond.selector.kind}\` selector on ordered-sequence equality (predicate DSL)`
|
|
218
|
-
: null));
|
|
219
|
-
case 'compare': {
|
|
220
|
-
const s = cond.compare.selector;
|
|
221
|
-
if (s.kind === 'calldata')
|
|
222
|
-
return 'EVM calldata comparison (predicate DSL)';
|
|
223
|
-
if (s.kind === 'value')
|
|
224
|
-
return 'tx.value comparison (predicate DSL)';
|
|
225
|
-
// The on-chain interpreter sees ONE authorized call - no
|
|
226
|
-
// `Context.sub_invocations` in v1 - so it cannot observe token
|
|
227
|
-
// movements. `amount` has no value to read, and `window_spent`
|
|
228
|
-
// accumulates BY that amount, so its counter would never move.
|
|
229
|
-
// Deriving either from the call payload would quietly swap "value
|
|
230
|
-
// actually moved" for "value the caller declared" - a weaker guarantee
|
|
231
|
-
// than the review card would be claiming.
|
|
232
|
-
//
|
|
233
|
-
// Rolling spend caps belong to the OZ `spending_limit` primitive (already
|
|
234
|
-
// audited, emitted by the OZ adapter). A per-call cap is expressible here
|
|
235
|
-
// as `arg_field`; bounding it with `invocation_count` gives an enforceable
|
|
236
|
-
// ceiling per window.
|
|
237
|
-
return unsourceableSelector(s);
|
|
238
|
-
}
|
|
239
|
-
// Recurse: a nested `and`/`or`/`not` must not smuggle a selector past the
|
|
240
|
-
// pre-scan, which only sees top-level constraints.
|
|
241
|
-
case 'and':
|
|
242
|
-
return cond.children.map(unsupportedConstruct).find((u) => u !== null) ?? null;
|
|
243
|
-
case 'or':
|
|
244
|
-
assertNoOracleDescendants(cond);
|
|
245
|
-
return cond.children.map(unsupportedConstruct).find((u) => u !== null) ?? null;
|
|
246
|
-
case 'not':
|
|
247
|
-
assertNoOracleDescendants(cond);
|
|
248
|
-
return unsupportedConstruct(cond.child);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
/** Selectors whose value the on-chain interpreter has no way to obtain. */
|
|
252
|
-
function unsourceableSelector(s) {
|
|
253
|
-
if (s.kind === 'amount') {
|
|
254
|
-
return `per-call amount comparison on ${s.token} - the interpreter cannot observe token movements; express a per-call cap with arg_field, or a rolling cap with the OZ spending_limit primitive`;
|
|
255
|
-
}
|
|
256
|
-
if (s.kind === 'window_spent') {
|
|
257
|
-
return `rolling spend cap on ${s.token} over ${s.windowSeconds}s - not enforceable by the interpreter; use the OZ spending_limit primitive, or bound per-call value with arg_field plus invocation_count`;
|
|
258
|
-
}
|
|
259
|
-
return null;
|
|
260
|
-
}
|
|
261
|
-
/** Lower one IR condition to a PredicateNode. Enforces the oracle position
|
|
262
|
-
* rule (oracle_price leaves must sit directly under the top-level `and`) and
|
|
263
|
-
* the self-call rule (`in` allowlist / `compare eq` vs the smart account
|
|
264
|
-
* address -> SCOPE_SELF_CALL). */
|
|
265
|
-
function lowerCondition(cond, config) {
|
|
266
|
-
switch (cond.op) {
|
|
267
|
-
// `out >= in * num/den`. The contract refuses den == 0 or a non-positive
|
|
268
|
-
// ratio at install, so a malformed floor fails loudly rather than
|
|
269
|
-
// silently inverting the comparison.
|
|
270
|
-
case 'slippage_floor':
|
|
271
|
-
return {
|
|
272
|
-
op: 'gte',
|
|
273
|
-
left: { kind: 'call_arg', index: cond.outArgIndex },
|
|
274
|
-
right: {
|
|
275
|
-
kind: 'call_arg_scaled',
|
|
276
|
-
index: cond.inArgIndex,
|
|
277
|
-
num: cond.num,
|
|
278
|
-
den: cond.den,
|
|
279
|
-
},
|
|
280
|
-
};
|
|
281
|
-
case 'and':
|
|
282
|
-
return { op: 'and', children: cond.children.map((c) => lowerCondition(c, config)) };
|
|
283
|
-
case 'or':
|
|
284
|
-
// `or` at this depth: oracle_price anywhere inside is invalid (would
|
|
285
|
-
// not be a direct child of the top-level `and`).
|
|
286
|
-
assertNoOracleDescendants(cond);
|
|
287
|
-
return { op: 'or', children: cond.children.map((c) => lowerCondition(c, config)) };
|
|
288
|
-
case 'not':
|
|
289
|
-
// `not` at this depth: oracle_price anywhere inside is invalid.
|
|
290
|
-
assertNoOracleDescendants(cond);
|
|
291
|
-
return { op: 'not', child: lowerCondition(cond.child, config) };
|
|
292
|
-
case 'in': {
|
|
293
|
-
assertNoOracleDescendants(cond);
|
|
294
|
-
for (const v of cond.values) {
|
|
295
|
-
assertNotSelfCallAddress(v, config);
|
|
296
|
-
}
|
|
297
|
-
// `in` is PURE set membership; the encoder sorts the haystack. An exact
|
|
298
|
-
// ordered sequence (e.g. swap hop path) is expressed as `eq_seq` and
|
|
299
|
-
// lowers to `eq(selector, literal_vec)` instead - never to `in` with an
|
|
300
|
-
// `ordered` flag.
|
|
301
|
-
return {
|
|
302
|
-
op: 'in',
|
|
303
|
-
needle: lowerSelector(cond.selector),
|
|
304
|
-
haystack: cond.values.map((v) => literalFromScalar(v, selectorScalarType(cond.selector))),
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
case 'eq_seq': {
|
|
308
|
-
assertNoOracleDescendants(cond);
|
|
309
|
-
for (const v of cond.values) {
|
|
310
|
-
assertNotSelfCallAddress(v, config);
|
|
311
|
-
}
|
|
312
|
-
// Exact ordered sequence equality: the right-hand side is a literal_vec
|
|
313
|
-
// whose element order is preserved verbatim by the encoder. `eq` does
|
|
314
|
-
// deep equality at evaluate time - this is the ONLY way to express an
|
|
315
|
-
// exact ordered sequence in the predicate grammar (the path of a swap).
|
|
316
|
-
return {
|
|
317
|
-
op: 'eq',
|
|
318
|
-
left: lowerSelector(cond.selector),
|
|
319
|
-
right: {
|
|
320
|
-
kind: 'literal_vec',
|
|
321
|
-
elements: cond.values.map((v) => literalFromScalar(v, selectorScalarType(cond.selector))),
|
|
322
|
-
},
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
case 'compare': {
|
|
326
|
-
// Self-call on an address eq.
|
|
327
|
-
if (cond.compare.operator === 'eq' &&
|
|
328
|
-
cond.compare.selector.kind === 'arg' &&
|
|
329
|
-
cond.compare.selector.scalarType === 'address') {
|
|
330
|
-
assertNotSelfCallAddress(cond.compare.value, config);
|
|
331
|
-
}
|
|
332
|
-
return {
|
|
333
|
-
op: cond.compare.operator,
|
|
334
|
-
left: lowerSelector(cond.compare.selector),
|
|
335
|
-
right: literalFromIRCompare(cond.compare),
|
|
336
|
-
};
|
|
119
|
+
/** Reject a value that targets the smart account's own address (a self-call
|
|
120
|
+
* is a structural privilege-escalation hole the interpreter forbids). */
|
|
121
|
+
/** Reject any address literal anywhere in the predicate that names the smart
|
|
122
|
+
* account itself: a policy permitting the account to call itself would let an
|
|
123
|
+
* agent re-enter the guarded account and escape the scope the rule pins. */
|
|
124
|
+
function assertNoSelfCall(node, config) {
|
|
125
|
+
const checkLeaf = (leaf) => {
|
|
126
|
+
if (leaf.kind === 'literal_vec') {
|
|
127
|
+
for (const e of leaf.elements)
|
|
128
|
+
checkLeaf(e);
|
|
129
|
+
return;
|
|
337
130
|
}
|
|
338
|
-
|
|
339
|
-
}
|
|
340
|
-
/** Lower an IR selector to the matching PredicateLeaf. */
|
|
341
|
-
function lowerSelector(s) {
|
|
342
|
-
switch (s.kind) {
|
|
343
|
-
case 'arg':
|
|
344
|
-
return { kind: 'call_arg', index: s.argIndex };
|
|
345
|
-
case 'arg_len':
|
|
346
|
-
return { kind: 'call_arg_len', index: s.argIndex };
|
|
347
|
-
case 'arg_field':
|
|
348
|
-
return { kind: 'call_arg_field', index: s.argIndex, element: s.element, field: s.field };
|
|
349
|
-
// `amount` / `window_spent` are filtered out by `unsupportedConstruct`
|
|
350
|
-
// before lowering - the interpreter cannot source either on chain.
|
|
351
|
-
// Reaching here means the pre-scan was bypassed; fail loudly rather than
|
|
352
|
-
// emit a leaf the contract will refuse.
|
|
353
|
-
case 'amount':
|
|
354
|
-
case 'window_spent':
|
|
355
|
-
throw new Error(`interpreter adapter cannot lower \`${s.kind}\`: it should have been reported as uncovered`);
|
|
356
|
-
case 'invocation_count':
|
|
357
|
-
return { kind: 'invocation_count_in_window', windowSecs: s.windowSeconds };
|
|
358
|
-
case 'now':
|
|
359
|
-
return { kind: 'now' };
|
|
360
|
-
case 'valid_until':
|
|
361
|
-
return { kind: 'valid_until' };
|
|
362
|
-
case 'oracle_price':
|
|
363
|
-
return { kind: 'oracle_price', asset: s.asset };
|
|
364
|
-
case 'calldata':
|
|
365
|
-
case 'value':
|
|
366
|
-
// Unreachable: the caller flagged these as Path-B before reaching here.
|
|
367
|
-
throw toolError('SYNTHESIS_ERROR', `selector kind \`${s.kind}\` is not lowerable to a predicate leaf`);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
/** Build a literal leaf from the right-hand side of an IRCompare, mapping the
|
|
371
|
-
* selector kind to the matching `literal_*` kind. The IR compare value is a
|
|
372
|
-
* raw string (i128-safe); the selector kind fixes the canonical wire type:
|
|
373
|
-
* - arg -> IR scalarType (set by the recorder/parser)
|
|
374
|
-
* - arg_len -> u32 (vec length is a small non-negative integer)
|
|
375
|
-
* - arg_field -> IR scalarType (the field's recorded type)
|
|
376
|
-
* - amount -> i128 (canonical Stellar token amount encoding)
|
|
377
|
-
* - window_spent -> i128 (canonical amount encoding)
|
|
378
|
-
* - oracle_price -> i128 (canonical price encoding)
|
|
379
|
-
* - invocation_count -> u32 (counts are small non-negative integers)
|
|
380
|
-
* - now / valid_until -> u64 (unix timestamps in seconds) */
|
|
381
|
-
function literalFromIRCompare(c) {
|
|
382
|
-
// An oracle comparand is not a bare literal: the interpreter refuses one,
|
|
383
|
-
// because assuming it shares the normalised 9-dp basis is what made a raw
|
|
384
|
-
// 14-dp threshold permit everything it was written to deny.
|
|
385
|
-
if (c.selector.kind === 'oracle_price') {
|
|
386
|
-
if (c.valueDecimals === undefined) {
|
|
387
|
-
throw toolError('ORACLE_THRESHOLD_BASIS_REQUIRED', 'An oracle price bound must declare the decimal basis of its threshold ' +
|
|
388
|
-
'(oracle prices normalise to 9 decimals).');
|
|
131
|
+
if (leaf.kind === 'literal_address' && leaf.value === config.smartAccountAddress) {
|
|
132
|
+
throw toolError('SCOPE_SELF_CALL', `value \`${leaf.value}\` is the smart account's own address (self-call in an allowlist / compare is rejected)`);
|
|
389
133
|
}
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
const scalarType = selectorScalarType(c.selector);
|
|
393
|
-
return literalFromScalar(c.value, scalarType);
|
|
394
|
-
}
|
|
395
|
-
function literalScalarForSelector(kind) {
|
|
396
|
-
switch (kind) {
|
|
397
|
-
case 'amount':
|
|
398
|
-
case 'window_spent':
|
|
399
|
-
case 'oracle_price':
|
|
400
|
-
return 'i128';
|
|
401
|
-
case 'invocation_count':
|
|
402
|
-
case 'arg_len':
|
|
403
|
-
return 'u32';
|
|
404
|
-
case 'now':
|
|
405
|
-
case 'valid_until':
|
|
406
|
-
return 'u64';
|
|
407
|
-
case 'arg':
|
|
408
|
-
case 'arg_field':
|
|
409
|
-
case 'calldata':
|
|
410
|
-
case 'value':
|
|
411
|
-
// arg / arg_field -> caller handles scalarType; calldata/value -> unreachable (Path-B).
|
|
412
|
-
return 'i128';
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
/** Build a literal leaf from a raw string value + an IRScalarType hint. */
|
|
416
|
-
function literalFromScalar(value, scalarType) {
|
|
417
|
-
switch (scalarType) {
|
|
418
|
-
case 'address':
|
|
419
|
-
return { kind: 'literal_address', value };
|
|
420
|
-
case 'i128':
|
|
421
|
-
case 'u128':
|
|
422
|
-
return { kind: 'literal_i128', value };
|
|
423
|
-
case 'u32':
|
|
424
|
-
return { kind: 'literal_u32', value: Number.parseInt(value, 10) };
|
|
425
|
-
case 'u64':
|
|
426
|
-
case 'i64':
|
|
427
|
-
return { kind: 'literal_u64', value };
|
|
428
|
-
case 'symbol':
|
|
429
|
-
return { kind: 'literal_symbol', value };
|
|
430
|
-
case 'bytes':
|
|
431
|
-
return { kind: 'literal_bytes', value };
|
|
432
|
-
case 'bool':
|
|
433
|
-
throw toolError('MALFORMED_PREDICATE', `boolean literal not supported in v1 predicate grammar`);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
/** Scalar type of an IRSelector for the purpose of building literal leaves
|
|
437
|
-
* (the right-hand side of `eq` / elements of an `in` haystack / elements of
|
|
438
|
-
* a `literal_vec`). Mirrors `literalScalarForSelector` for OZ extensions and
|
|
439
|
-
* uses the selector's own `scalarType` for `arg` and `arg_field` selectors. */
|
|
440
|
-
function selectorScalarType(selector) {
|
|
441
|
-
if (selector.kind === 'arg')
|
|
442
|
-
return selector.scalarType;
|
|
443
|
-
if (selector.kind === 'arg_field')
|
|
444
|
-
return selector.scalarType;
|
|
445
|
-
return literalScalarForSelector(selector.kind);
|
|
446
|
-
}
|
|
447
|
-
/** Walk a condition tree and throw if any oracle_price leaf is found anywhere
|
|
448
|
-
* inside. Used by `lowerCondition` for `not`, `or`, and `in` - the three
|
|
449
|
-
* positions where oracle leaves would not be direct children of the
|
|
450
|
-
* top-level `and`. */
|
|
451
|
-
function assertNoOracleDescendants(node) {
|
|
452
|
-
if (containsOracle(node)) {
|
|
453
|
-
throw toolError('ORACLE_LEAF_INVALID_POSITION', 'oracle_price leaves must sit directly under the top-level `and`');
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
function containsOracle(node) {
|
|
134
|
+
};
|
|
457
135
|
switch (node.op) {
|
|
458
|
-
case 'slippage_floor':
|
|
459
|
-
return false;
|
|
460
|
-
case 'compare':
|
|
461
|
-
return node.compare.selector.kind === 'oracle_price';
|
|
462
|
-
case 'in':
|
|
463
|
-
return node.selector.kind === 'oracle_price';
|
|
464
|
-
case 'eq_seq':
|
|
465
|
-
return node.selector.kind === 'oracle_price';
|
|
466
|
-
case 'not':
|
|
467
|
-
return containsOracle(node.child);
|
|
468
136
|
case 'and':
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
}
|
|
473
|
-
/** Reject a value that targets the smart account's own address (a self-call
|
|
474
|
-
* is a structural privilege-escalation hole the interpreter forbids). */
|
|
475
|
-
function assertNotSelfCallAddress(value, config) {
|
|
476
|
-
if (value === config.smartAccountAddress) {
|
|
477
|
-
throw toolError('SCOPE_SELF_CALL', `value \`${value}\` is the smart account's own address (self-call in an allowlist / compare is rejected)`);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
/** Tighten-only oracle-params gate. Any widening value (above the wasm-level
|
|
481
|
-
* defaults) throws ORACLE_PARAMS_OUT_OF_RANGE at compile time. */
|
|
482
|
-
function assertOracleParamsTighten(params) {
|
|
483
|
-
if (!params)
|
|
484
|
-
return;
|
|
485
|
-
if (params.maxStalenessSeconds !== undefined &&
|
|
486
|
-
params.maxStalenessSeconds > ORACLE_DEFAULTS.maxStalenessSeconds) {
|
|
487
|
-
throw toolError('ORACLE_PARAMS_OUT_OF_RANGE', `maxStalenessSeconds ${params.maxStalenessSeconds} exceeds default ${ORACLE_DEFAULTS.maxStalenessSeconds}`);
|
|
488
|
-
}
|
|
489
|
-
if (params.maxDeviationBps !== undefined &&
|
|
490
|
-
params.maxDeviationBps > ORACLE_DEFAULTS.maxDeviationBps) {
|
|
491
|
-
throw toolError('ORACLE_PARAMS_OUT_OF_RANGE', `maxDeviationBps ${params.maxDeviationBps} exceeds default ${ORACLE_DEFAULTS.maxDeviationBps}`);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
/** Human-readable descriptor for a construct the interpreter adapter cannot
|
|
495
|
-
* express. Mirrors the OZ adapter's `describeCondition` for parity. */
|
|
496
|
-
function describeCondition(cond) {
|
|
497
|
-
switch (cond.op) {
|
|
498
|
-
case 'slippage_floor':
|
|
499
|
-
return `slippage floor: arg[${cond.outArgIndex}] >= arg[${cond.inArgIndex}] * ${cond.num}/${cond.den}`;
|
|
137
|
+
for (const c of node.children)
|
|
138
|
+
assertNoSelfCall(c, config);
|
|
139
|
+
return;
|
|
500
140
|
case 'in':
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
return 'negated condition (predicate DSL)';
|
|
506
|
-
case 'and':
|
|
507
|
-
case 'or':
|
|
508
|
-
return `nested ${cond.op} condition (predicate DSL)`;
|
|
509
|
-
case 'compare': {
|
|
510
|
-
const s = cond.compare.selector;
|
|
511
|
-
switch (s.kind) {
|
|
512
|
-
case 'oracle_price':
|
|
513
|
-
return `oracle price condition on ${s.asset}`;
|
|
514
|
-
case 'invocation_count':
|
|
515
|
-
return `invocation-count window (${s.windowSeconds}s) condition`;
|
|
516
|
-
case 'window_spent':
|
|
517
|
-
return `spend-window comparison with operator '${cond.compare.operator}'`;
|
|
518
|
-
case 'amount':
|
|
519
|
-
return `per-call amount comparison on ${s.token}`;
|
|
520
|
-
case 'arg':
|
|
521
|
-
return `argument comparison on arg ${s.argIndex}`;
|
|
522
|
-
case 'arg_len':
|
|
523
|
-
return `vec length comparison on arg ${s.argIndex}`;
|
|
524
|
-
case 'arg_field':
|
|
525
|
-
return `map field comparison on arg ${s.argIndex}.${s.field}`;
|
|
526
|
-
case 'calldata':
|
|
527
|
-
return 'EVM calldata comparison';
|
|
528
|
-
case 'value':
|
|
529
|
-
return 'tx.value comparison';
|
|
530
|
-
case 'now':
|
|
531
|
-
case 'valid_until':
|
|
532
|
-
return 'time comparison';
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
function describeSelector(s) {
|
|
538
|
-
switch (s.kind) {
|
|
539
|
-
case 'arg':
|
|
540
|
-
return `arg ${s.argIndex}`;
|
|
541
|
-
case 'arg_len':
|
|
542
|
-
return `arg_len(${s.argIndex})`;
|
|
543
|
-
case 'arg_field':
|
|
544
|
-
return `arg_field(${s.argIndex}, ${s.element}, ${s.field})`;
|
|
545
|
-
case 'amount':
|
|
546
|
-
return `amount(${s.token})`;
|
|
547
|
-
case 'window_spent':
|
|
548
|
-
return `window_spent(${s.token})`;
|
|
549
|
-
case 'oracle_price':
|
|
550
|
-
return `oracle_price(${s.asset})`;
|
|
551
|
-
case 'invocation_count':
|
|
552
|
-
return `invocation_count(${s.windowSeconds}s)`;
|
|
553
|
-
case 'calldata':
|
|
554
|
-
return `calldata[${s.offset}:${s.offset + s.length}]`;
|
|
141
|
+
// The needle is a selector; only the haystack carries literals.
|
|
142
|
+
for (const h of node.haystack)
|
|
143
|
+
checkLeaf(h);
|
|
144
|
+
return;
|
|
555
145
|
default:
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
}
|
|
559
|
-
function simulateStub() {
|
|
560
|
-
return {
|
|
561
|
-
backend: 'ts-model',
|
|
562
|
-
permitted: null,
|
|
563
|
-
evaluations: [],
|
|
564
|
-
notes: ['stub: real permit/deny semantics wiring is a later phase'],
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
/** Canonical JSON with recursively sorted object keys (stable across runs). */
|
|
568
|
-
function canonicalStringify(value) {
|
|
569
|
-
return JSON.stringify(sortKeys(value));
|
|
570
|
-
}
|
|
571
|
-
function sortKeys(value) {
|
|
572
|
-
if (Array.isArray(value))
|
|
573
|
-
return value.map(sortKeys);
|
|
574
|
-
if (value && typeof value === 'object') {
|
|
575
|
-
const out = {};
|
|
576
|
-
for (const key of Object.keys(value).sort()) {
|
|
577
|
-
out[key] = sortKeys(value[key]);
|
|
578
|
-
}
|
|
579
|
-
return out;
|
|
146
|
+
checkLeaf(node.left);
|
|
147
|
+
checkLeaf(node.right);
|
|
580
148
|
}
|
|
581
|
-
return value;
|
|
582
149
|
}
|
|
583
150
|
/** Build a synthetic Error carrying the ToolError code/severity/retryable
|
|
584
151
|
* fields the existing ToolError shape uses (the encoder pattern). Callers
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ErrorCode = 'RECORDING_FAILED' | 'RECORDING_VALIDATION_FAILED' | 'SCOPE_UNRESOLVED' | 'SYNTHESIS_ERROR' | 'MALFORMED_PREDICATE' | 'SIMULATION_ERROR' | 'VERIFICATION_FAILED' | 'DENY_CASE_FAILURE' | 'PERMIT_CASE_FAILED' | 'SUMMARY_DRIFT' | 'INSTALL_BUILD_FAILED' | 'INSTALL_CONFIRM_MISSING' | 'INSTALL_CONFIRM_EXPIRED' | 'REVOKE_BUILD_FAILED' | 'REVOKE_CONFIRM_MISSING' | 'USER_REJECTED_SIGN' | 'WALLET_TIMEOUT' | 'WALLET_UNAVAILABLE' | 'PREDICATE_TOO_LARGE' | 'PREDICATE_TOO_DEEP' | 'TOO_MANY_LEAVES' | 'IN_OPERAND_LIMIT' | '
|
|
1
|
+
export type ErrorCode = 'RECORDING_FAILED' | 'RECORDING_VALIDATION_FAILED' | 'SCOPE_UNRESOLVED' | 'SYNTHESIS_ERROR' | 'MALFORMED_PREDICATE' | 'SIMULATION_ERROR' | 'VERIFICATION_FAILED' | 'DENY_CASE_FAILURE' | 'PERMIT_CASE_FAILED' | 'SUMMARY_DRIFT' | 'INSTALL_BUILD_FAILED' | 'INSTALL_CONFIRM_MISSING' | 'INSTALL_CONFIRM_EXPIRED' | 'REVOKE_BUILD_FAILED' | 'REVOKE_CONFIRM_MISSING' | 'USER_REJECTED_SIGN' | 'WALLET_TIMEOUT' | 'WALLET_UNAVAILABLE' | 'PREDICATE_TOO_LARGE' | 'PREDICATE_TOO_DEEP' | 'TOO_MANY_LEAVES' | 'IN_OPERAND_LIMIT' | 'POLICY_CAP_EXCEEDED' | 'WASM_TOO_LARGE' | 'MASTER_AUTH_REQUIRED' | 'NONCE_REPLAY' | 'VERSION_MISMATCH' | 'ARITHMETIC_OVERFLOW' | 'AMOUNT_OVERFLOW' | 'RULE_SIGNERS_CHANGED' | 'SCOPE_SELF_CALL' | 'ARG_MISMATCH' | 'CONTRACT_SCOPE' | 'UNSUPPORTED_NODE' | 'STATEFUL_BOUND' | 'NOT_IN_ALLOWLIST' | 'COMPILE_OK' | 'COMPILE_GATE_FAILED';
|
|
2
2
|
export interface ToolError {
|
|
3
3
|
code: ErrorCode;
|
|
4
4
|
message: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
export * from './adapters/oz/index.ts';
|
|
2
1
|
export * from './errors.ts';
|
|
3
|
-
export * from './ir/index.ts';
|
|
4
|
-
export * from './mandate/index.ts';
|
|
5
2
|
export * from './predicate/index.ts';
|
|
6
3
|
export * from './record/index.ts';
|
|
7
4
|
export * from './registry/index.ts';
|
|
8
5
|
export * from './review-card/index.ts';
|
|
9
|
-
export * from './
|
|
6
|
+
export * from './simulate/index.ts';
|
|
10
7
|
export * from './synth/index.ts';
|
|
11
8
|
export * from './types.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
export * from "./adapters/oz/index.js";
|
|
2
1
|
export * from "./errors.js";
|
|
3
|
-
export * from "./ir/index.js";
|
|
4
|
-
export * from "./mandate/index.js";
|
|
5
2
|
export * from "./predicate/index.js";
|
|
6
3
|
export * from "./record/index.js";
|
|
7
4
|
export * from "./registry/index.js";
|
|
8
5
|
export * from "./review-card/index.js";
|
|
9
|
-
export * from "./
|
|
6
|
+
export * from "./simulate/index.js";
|
|
10
7
|
export * from "./synth/index.js";
|
|
11
8
|
export * from "./types.js";
|