@crediolabs/policy-synth 0.1.16 → 0.1.18
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 +43 -246
- package/dist/adapters/interpreter/adapter.d.ts +6 -7
- package/dist/adapters/interpreter/adapter.js +28 -48
- package/dist/adapters/oz/adapter.js +12 -13
- package/dist/codegen/compile-gate.js +5 -0
- package/dist/codegen/template.js +17 -0
- package/dist/install/build-add-context-rule.js +16 -45
- package/dist/install/build-install-policy.d.ts +12 -5
- package/dist/install/build-install-policy.js +32 -23
- package/dist/install/get-interpreter-info.js +2 -2
- package/dist/install/index.d.ts +1 -0
- package/dist/install/index.js +15 -0
- package/dist/install/oz-auth.js +5 -3
- package/dist/predicate/decode.js +1 -1
- package/dist/predicate/encode.js +171 -10
- package/dist/record/decode.js +5 -6
- package/dist/registry/protocols.d.ts +1 -1
- package/dist/registry/protocols.js +1 -1
- package/dist/review-card/builder.d.ts +6 -0
- package/dist/review-card/builder.js +9 -1
- package/dist/run/index.d.ts +14 -13
- package/dist/run/index.js +80 -67
- package/dist/run/schemas.d.ts +193 -11
- package/dist/run/schemas.js +59 -17
- package/dist/synth/compose-from-recording.d.ts +10 -15
- package/dist/synth/compose-from-recording.js +79 -124
- package/dist/synth/deny-cases.d.ts +5 -0
- package/dist/synth/deny-cases.js +52 -13
- package/dist/synth/evaluate.js +69 -119
- package/dist/synth/harness.d.ts +13 -1
- package/dist/synth/harness.js +22 -1
- package/dist/synth/index.d.ts +1 -1
- package/dist/synth/synthesize-from-recording.d.ts +31 -21
- package/dist/synth/synthesize-from-recording.js +129 -155
- package/dist-cjs/adapters/interpreter/adapter.d.ts +6 -7
- package/dist-cjs/adapters/interpreter/adapter.js +28 -48
- package/dist-cjs/adapters/oz/adapter.js +12 -13
- package/dist-cjs/codegen/compile-gate.js +5 -0
- package/dist-cjs/codegen/template.js +17 -0
- package/dist-cjs/install/build-add-context-rule.js +16 -45
- package/dist-cjs/install/build-install-policy.d.ts +12 -5
- package/dist-cjs/install/build-install-policy.js +32 -23
- package/dist-cjs/install/get-interpreter-info.js +2 -2
- package/dist-cjs/install/index.d.ts +1 -0
- package/dist-cjs/install/index.js +21 -0
- package/dist-cjs/install/oz-auth.js +5 -3
- package/dist-cjs/predicate/decode.js +1 -1
- package/dist-cjs/predicate/encode.js +171 -10
- package/dist-cjs/record/decode.js +5 -6
- package/dist-cjs/registry/protocols.d.ts +1 -1
- package/dist-cjs/registry/protocols.js +1 -1
- package/dist-cjs/review-card/builder.d.ts +6 -0
- package/dist-cjs/review-card/builder.js +9 -1
- package/dist-cjs/run/index.d.ts +14 -13
- package/dist-cjs/run/index.js +80 -67
- package/dist-cjs/run/schemas.d.ts +193 -11
- package/dist-cjs/run/schemas.js +59 -17
- package/dist-cjs/synth/compose-from-recording.d.ts +10 -15
- package/dist-cjs/synth/compose-from-recording.js +79 -124
- package/dist-cjs/synth/deny-cases.d.ts +5 -0
- package/dist-cjs/synth/deny-cases.js +52 -13
- package/dist-cjs/synth/evaluate.js +69 -119
- package/dist-cjs/synth/harness.d.ts +13 -1
- package/dist-cjs/synth/harness.js +22 -1
- package/dist-cjs/synth/index.d.ts +1 -1
- package/dist-cjs/synth/synthesize-from-recording.d.ts +31 -21
- package/dist-cjs/synth/synthesize-from-recording.js +129 -153
- package/package.json +11 -4
- package/src/adapters/interpreter/adapter.ts +28 -48
- package/src/adapters/oz/adapter.ts +12 -13
- package/src/codegen/compile-gate.ts +5 -0
- package/src/codegen/template.ts +17 -0
- package/src/install/build-add-context-rule.ts +17 -55
- package/src/install/build-install-policy.ts +41 -23
- package/src/install/get-interpreter-info.ts +2 -2
- package/src/install/index.ts +21 -0
- package/src/install/oz-auth.ts +5 -3
- package/src/predicate/decode.ts +1 -1
- package/src/predicate/encode.ts +176 -10
- package/src/record/decode.ts +5 -6
- package/src/registry/protocols.ts +1 -1
- package/src/review-card/builder.ts +17 -1
- package/src/run/index.ts +117 -91
- package/src/run/schemas.ts +64 -16
- package/src/synth/compose-from-recording.ts +87 -132
- package/src/synth/deny-cases.ts +59 -13
- package/src/synth/evaluate.ts +70 -118
- package/src/synth/harness.ts +29 -1
- package/src/synth/index.ts +1 -0
- package/src/synth/synthesize-from-recording.ts +209 -192
- package/src/contracts/policy-template/OZ_POLICY_TRAIT.md +0 -196
|
@@ -2,26 +2,9 @@
|
|
|
2
2
|
// src/adapters/interpreter/adapter.ts - the interpreter-policy CustodyAdapter.
|
|
3
3
|
//
|
|
4
4
|
// Compiles a PolicyIR to a single interpreter `PolicyDocument` + `PolicyRef`
|
|
5
|
-
// carrying the canonical predicate encoding
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
// cover the canonical language subset. The compose step (P3) routes IR
|
|
9
|
-
// constructs between them.
|
|
10
|
-
//
|
|
11
|
-
// What it lowers (every IR construct the predicate DSL expresses):
|
|
12
|
-
// - IRLogic and/or -> PredicateNode and/or
|
|
13
|
-
// - IRLogic not -> PredicateNode not
|
|
14
|
-
// - IRCompare -> selector(left) vs literal(right), op carried over
|
|
15
|
-
// - IR `in` -> needle=selector, haystack=literals (PURESET
|
|
16
|
-
// membership; the haystack is always sorted by the
|
|
17
|
-
// encoder)
|
|
18
|
-
// - IR `eq_seq` -> eq(selectorLeaf, literal_vec([...])) - exact ordered
|
|
19
|
-
// sequence equality; element order is preserved
|
|
20
|
-
// verbatim (the encoder does NOT sort the vec)
|
|
21
|
-
// - IRSelector -> matching PredicateLeaf (see lowerSelector)
|
|
22
|
-
// - scope.contract -> sibling `call_contract == <contract>` (always
|
|
23
|
-
// emitted when set)
|
|
24
|
-
// - scope.method -> sibling `call_fn == <method>`
|
|
5
|
+
// carrying the canonical predicate encoding from `predicate/encode.ts`. Second
|
|
6
|
+
// backend (the OZ built-in adapter is the first); the compose step (P3) routes
|
|
7
|
+
// IR constructs between them.
|
|
25
8
|
//
|
|
26
9
|
// Three fail-closed enforcement gates (per spec):
|
|
27
10
|
// - oracle_price leaves MUST sit directly under the top-level `and`; nesting
|
|
@@ -43,7 +26,7 @@ const encode_ts_1 = require("../../predicate/encode.js");
|
|
|
43
26
|
/** [VERIFY] NOT a real deployed address. The interpreter is a per-network
|
|
44
27
|
* deploy artifact we do not have yet; install is a later phase. */
|
|
45
28
|
exports.PLACEHOLDER_INTERPRETER_ADDRESS = 'VERIFY-interpreter-address';
|
|
46
|
-
/** Wasm-level oracle defaults (mirrors
|
|
29
|
+
/** Wasm-level oracle defaults (mirrors the interpreter's `OracleParams`).
|
|
47
30
|
* Per-policy overrides may TIGHTEN only - they may never exceed these. */
|
|
48
31
|
exports.ORACLE_DEFAULTS = {
|
|
49
32
|
maxStalenessSeconds: 600,
|
|
@@ -52,17 +35,15 @@ exports.ORACLE_DEFAULTS = {
|
|
|
52
35
|
const CAPABILITIES = {
|
|
53
36
|
supportsSpendWindow: true,
|
|
54
37
|
supportsThreshold: false, // thresholds are the OZ adapter's job
|
|
55
|
-
//
|
|
56
|
-
// leaf at install.
|
|
57
|
-
// validUntilLedger, which the smart account enforces - not as a predicate.
|
|
38
|
+
// Expiry is via the context rule's validUntilLedger, not a predicate - the
|
|
39
|
+
// interpreter refuses a `valid_until` leaf at install.
|
|
58
40
|
supportsTimeExpiry: false,
|
|
59
41
|
supportsOraclePrice: true,
|
|
60
42
|
supportsInvocationCount: true,
|
|
61
43
|
supportsGeneralPredicate: true,
|
|
62
44
|
};
|
|
63
|
-
/** Parse confidence for a deterministic (non-decoded) input: full
|
|
64
|
-
*
|
|
65
|
-
* not applicable and confidence is 1. */
|
|
45
|
+
/** Parse confidence for a deterministic (non-decoded) input: full (1.0). A
|
|
46
|
+
* mandate needs no decoding, so the gate is not applicable. */
|
|
66
47
|
const FULL_PARSE_CONFIDENCE = {
|
|
67
48
|
overall: 1,
|
|
68
49
|
knownContracts: [],
|
|
@@ -82,12 +63,11 @@ function createInterpreterAdapter(config) {
|
|
|
82
63
|
}
|
|
83
64
|
/** Lower a single IR rule to the canonical pre-encoding `PredicateNode`. The
|
|
84
65
|
* orchestrator uses this to wire the self-verify + minimise pipeline: after
|
|
85
|
-
* `compile(ir)` succeeds
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* `
|
|
90
|
-
* here; callers that need it should use the result of `compile(ir)`. */
|
|
66
|
+
* `compile(ir)` succeeds it re-derives the PredicateNode via this helper to
|
|
67
|
+
* drive `minimize` and `runHarness` on the SAME shape the encoder saw. Pure
|
|
68
|
+
* and deterministic: same `rule + config` -> byte-identical PredicateNode.
|
|
69
|
+
* The `uncovered` list is NOT re-derived - callers needing it must use
|
|
70
|
+
* `compile(ir)`. */
|
|
91
71
|
function lowerRuleToPredicate(rule, config) {
|
|
92
72
|
return lowerRule(rule, config).predicate;
|
|
93
73
|
}
|
|
@@ -137,9 +117,9 @@ function compile(ir, config) {
|
|
|
137
117
|
function lowerRule(rule, config) {
|
|
138
118
|
const uncovered = [];
|
|
139
119
|
// scope -> context rule + sibling predicates. contract/method each become
|
|
140
|
-
// their own `eq` leaf and are merged into the top-level and alongside the
|
|
141
|
-
// constraints.
|
|
142
|
-
// position rule
|
|
120
|
+
// their own `eq` leaf and are merged into the top-level `and` alongside the
|
|
121
|
+
// constraints. The top-level MUST be `and` so oracle leaves sit directly
|
|
122
|
+
// under it (mandatory per the oracle position rule + canonical hash stability).
|
|
143
123
|
const scopeContract = rule.scope.contract;
|
|
144
124
|
const scopeMethod = rule.scope.method;
|
|
145
125
|
if (rule.scope.chainId !== undefined) {
|
|
@@ -247,18 +227,18 @@ function unsupportedConstruct(cond) {
|
|
|
247
227
|
return 'EVM calldata comparison (predicate DSL)';
|
|
248
228
|
if (s.kind === 'value')
|
|
249
229
|
return 'tx.value comparison (predicate DSL)';
|
|
250
|
-
// The on-chain interpreter sees ONE authorized call -
|
|
251
|
-
// `Context.sub_invocations` in v1 - so it cannot observe
|
|
252
|
-
//
|
|
253
|
-
//
|
|
254
|
-
//
|
|
230
|
+
// The on-chain interpreter sees ONE authorized call - no
|
|
231
|
+
// `Context.sub_invocations` in v1 - so it cannot observe token
|
|
232
|
+
// movements. `amount` has no value to read, and `window_spent`
|
|
233
|
+
// accumulates BY that amount, so its counter would never move.
|
|
234
|
+
// Deriving either from the call payload would quietly swap "value
|
|
255
235
|
// actually moved" for "value the caller declared" - a weaker guarantee
|
|
256
236
|
// than the review card would be claiming.
|
|
257
237
|
//
|
|
258
|
-
// Rolling spend caps belong to the OZ `spending_limit` primitive
|
|
259
|
-
//
|
|
260
|
-
//
|
|
261
|
-
//
|
|
238
|
+
// Rolling spend caps belong to the OZ `spending_limit` primitive (already
|
|
239
|
+
// audited, emitted by the OZ adapter). A per-call cap is expressible here
|
|
240
|
+
// as `arg_field`; bounding it with `invocation_count` gives an enforceable
|
|
241
|
+
// ceiling per window.
|
|
262
242
|
return unsourceableSelector(s);
|
|
263
243
|
}
|
|
264
244
|
// Recurse: a nested `and`/`or`/`not` must not smuggle a selector past the
|
|
@@ -372,9 +352,9 @@ function lowerSelector(s) {
|
|
|
372
352
|
case 'arg_field':
|
|
373
353
|
return { kind: 'call_arg_field', index: s.argIndex, element: s.element, field: s.field };
|
|
374
354
|
// `amount` / `window_spent` are filtered out by `unsupportedConstruct`
|
|
375
|
-
// before lowering - the interpreter cannot source either on chain.
|
|
376
|
-
// here means the pre-scan was bypassed
|
|
377
|
-
// leaf the contract will refuse.
|
|
355
|
+
// before lowering - the interpreter cannot source either on chain.
|
|
356
|
+
// Reaching here means the pre-scan was bypassed; fail loudly rather than
|
|
357
|
+
// emit a leaf the contract will refuse.
|
|
378
358
|
case 'amount':
|
|
379
359
|
case 'window_spent':
|
|
380
360
|
throw new Error(`interpreter adapter cannot lower \`${s.kind}\`: it should have been reported as uncovered`);
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// Anything needing a capability this backend lacks (oracle price, invocation
|
|
11
11
|
// count, per-arg comparison/allowlist, guard, nested boolean predicate) is NOT
|
|
12
12
|
// emitted: it is named in `uncovered` and `covered` is set false. Nothing is
|
|
13
|
-
// silently dropped
|
|
13
|
+
// silently dropped.
|
|
14
14
|
//
|
|
15
15
|
// OZ built-in policy instance addresses are per-network deploy artifacts we do
|
|
16
16
|
// not have yet (install is a later phase). They are injected via config; week-1
|
|
@@ -32,9 +32,8 @@ exports.PLACEHOLDER_OZ_INSTANCES = {
|
|
|
32
32
|
function placeholderOzConfig(network) {
|
|
33
33
|
return { network, instances: exports.PLACEHOLDER_OZ_INSTANCES };
|
|
34
34
|
}
|
|
35
|
-
/** Parse confidence for a deterministic (non-decoded) input: full
|
|
36
|
-
*
|
|
37
|
-
* not applicable and confidence is 1. */
|
|
35
|
+
/** Parse confidence for a deterministic (non-decoded) input: full (1.0). A
|
|
36
|
+
* mandate needs no decoding, so the gate is not applicable. */
|
|
38
37
|
const FULL_PARSE_CONFIDENCE = {
|
|
39
38
|
overall: 1,
|
|
40
39
|
knownContracts: [],
|
|
@@ -88,10 +87,10 @@ function compile(ir, config) {
|
|
|
88
87
|
function lowerRule(rule, config) {
|
|
89
88
|
const uncovered = [];
|
|
90
89
|
const policyRefs = [];
|
|
91
|
-
// scope -> context rule type. OZ scopes by contract (CallContract); a
|
|
92
|
-
// method-level restriction is
|
|
93
|
-
//
|
|
94
|
-
//
|
|
90
|
+
// scope -> context rule type. OZ scopes by contract (CallContract); a
|
|
91
|
+
// method-level restriction is flagged as not covered because CallContract
|
|
92
|
+
// alone permits other methods on the same contract (e.g. an unbounded approve
|
|
93
|
+
// alongside a capped transfer).
|
|
95
94
|
const contextRuleType = rule.scope.contract !== undefined
|
|
96
95
|
? { kind: 'call_contract', contract: rule.scope.contract }
|
|
97
96
|
: { kind: 'default' };
|
|
@@ -120,8 +119,8 @@ function lowerRule(rule, config) {
|
|
|
120
119
|
uncovered.push(`guard: ${describeCondition(rule.guard)}`);
|
|
121
120
|
}
|
|
122
121
|
// constraints -> spending_limit where they match; else not covered. The OZ
|
|
123
|
-
// spending_limit
|
|
124
|
-
//
|
|
122
|
+
// spending_limit takes `{ spending_limit: i128, period_ledgers: u32 }` and
|
|
123
|
+
// has NO token param: it only accepts a CallContract context rule
|
|
125
124
|
// (OnlyCallContractAllowed) and limits transfers of that context's contract,
|
|
126
125
|
// so the spent token must equal the scope contract, and the window is a
|
|
127
126
|
// ledger count (~5s/ledger), not seconds.
|
|
@@ -149,7 +148,7 @@ function lowerRule(rule, config) {
|
|
|
149
148
|
}
|
|
150
149
|
// approval.threshold -> simple/weighted threshold primitive. A threshold < 1
|
|
151
150
|
// is not a real M-of-N gate (0 approvals authorises everything), so refuse to
|
|
152
|
-
// emit a no-op primitive and flag it as not covered
|
|
151
|
+
// emit a no-op primitive and flag it as not covered.
|
|
153
152
|
if (rule.approval) {
|
|
154
153
|
if (!Number.isInteger(rule.approval.threshold) || rule.approval.threshold < 1) {
|
|
155
154
|
uncovered.push(`approval threshold ${rule.approval.threshold} is not a positive integer (a 0 or negative threshold is not an M-of-N gate)`);
|
|
@@ -213,8 +212,8 @@ function matchSpendingLimit(c) {
|
|
|
213
212
|
function describeCondition(cond) {
|
|
214
213
|
switch (cond.op) {
|
|
215
214
|
case 'slippage_floor':
|
|
216
|
-
//
|
|
217
|
-
//
|
|
215
|
+
// OZ primitives bound a value against a constant; this bounds one call
|
|
216
|
+
// argument against another, which none of them can express.
|
|
218
217
|
return `slippage floor on arg[${cond.outArgIndex}] (OZ built-ins cannot bound one argument against another)`;
|
|
219
218
|
case 'in':
|
|
220
219
|
return `value allowlist on ${describeSelector(cond.selector)} (arg allowlist)`;
|
|
@@ -79,6 +79,11 @@ publish = false
|
|
|
79
79
|
|
|
80
80
|
[lib]
|
|
81
81
|
crate-type = ["cdylib"]
|
|
82
|
+
# The gate writes the source beside the manifest rather than under src/, so
|
|
83
|
+
# the path is stated. Without it cargo looks for src/lib.rs and fails to
|
|
84
|
+
# parse the manifest before it ever compiles anything, which reads as a
|
|
85
|
+
# broken generator rather than a broken scaffold.
|
|
86
|
+
path = "lib.rs"
|
|
82
87
|
|
|
83
88
|
[dependencies]
|
|
84
89
|
soroban-sdk = "22"
|
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
// src/codegen/template.ts - deterministic Rust source generator for the OZ
|
|
3
3
|
// `Policy` escape-hatch skeleton.
|
|
4
4
|
//
|
|
5
|
+
// SUPERSEDED. The architecture this belongs to no longer exists. A deployed
|
|
6
|
+
// policy involves exactly two contracts, the OZ smart account and one
|
|
7
|
+
// immutable interpreter, and the synthesiser emits policy DATA rather than
|
|
8
|
+
// code. Nothing on the synthesis path reaches this module, and no install can
|
|
9
|
+
// produce a contract from it. When a constraint falls outside the grammar the
|
|
10
|
+
// answer is to version the synthesiser and the interpreter together, not to
|
|
11
|
+
// put unaudited Rust on chain per policy.
|
|
12
|
+
//
|
|
13
|
+
// Deleting it is a decision nobody has taken yet, not a dependency question.
|
|
14
|
+
// `compile-gate.ts` takes a Rust string and knows nothing about this module,
|
|
15
|
+
// and its tests compile a hardcoded fixture, so the gate keeps working either
|
|
16
|
+
// way. What deleting this would remove is the only in-repo producer of policy
|
|
17
|
+
// Rust for the gate to check. Do not read its presence as the product
|
|
18
|
+
// generating contracts, and do not wire it into the synthesis path.
|
|
19
|
+
//
|
|
20
|
+
// What follows describes the abandoned design.
|
|
21
|
+
//
|
|
5
22
|
// This is the LAST-RESORT tool for constraints the v1 DSL cannot express. It
|
|
6
23
|
// lives OUT of the audited happy-path surface; the synthesiser never emits it
|
|
7
24
|
// automatically. It mirrors Zodiac Roles' `Custom` operator: a hand-written
|
|
@@ -144,13 +144,12 @@ function encodePoliciesMap(args) {
|
|
|
144
144
|
const entries = [];
|
|
145
145
|
for (const ref of args.policies) {
|
|
146
146
|
if (ref.kind === 'interpreter') {
|
|
147
|
-
const val = encodePolicyInstallParams(args);
|
|
148
147
|
entries.push(new stellar_sdk_1.xdr.ScMapEntry({
|
|
149
148
|
key: stellar_sdk_1.Address.fromString(ref.interpreterAddress).toScVal(),
|
|
150
|
-
val,
|
|
149
|
+
val: encodePolicyInstallParams(args),
|
|
151
150
|
}));
|
|
152
151
|
}
|
|
153
|
-
if (ref.kind === 'oz_builtin') {
|
|
152
|
+
else if (ref.kind === 'oz_builtin') {
|
|
154
153
|
entries.push(new stellar_sdk_1.xdr.ScMapEntry({
|
|
155
154
|
key: stellar_sdk_1.Address.fromString(ref.instanceAddress).toScVal(),
|
|
156
155
|
val: encodeOzPrimitiveParams(ref.primitive),
|
|
@@ -225,48 +224,20 @@ function encodePolicyInstallParams(args) {
|
|
|
225
224
|
if (computedHash !== args.predicateHash) {
|
|
226
225
|
throw limitError('INSTALL_BUILD_FAILED', `predicateHash ${args.predicateHash.slice(0, 16)}... does not match sha256(encodedPredicate) ${computedHash.slice(0, 16)}...`);
|
|
227
226
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
entries.push(new stellar_sdk_1.xdr.ScMapEntry({ key, val: stellar_sdk_1.xdr.ScVal.scvBytes(predicate) }));
|
|
243
|
-
break;
|
|
244
|
-
case 'predicate_hash':
|
|
245
|
-
entries.push(new stellar_sdk_1.xdr.ScMapEntry({
|
|
246
|
-
key,
|
|
247
|
-
val: stellar_sdk_1.xdr.ScVal.scvBytes(Buffer.from(args.predicateHash, 'hex')),
|
|
248
|
-
}));
|
|
249
|
-
break;
|
|
250
|
-
case 'oracle_max_staleness_seconds':
|
|
251
|
-
entries.push(new stellar_sdk_1.xdr.ScMapEntry({
|
|
252
|
-
key,
|
|
253
|
-
val: encodeOptionU32(args.oracleParams?.maxStalenessSeconds),
|
|
254
|
-
}));
|
|
255
|
-
break;
|
|
256
|
-
case 'oracle_max_deviation_bps':
|
|
257
|
-
entries.push(new stellar_sdk_1.xdr.ScMapEntry({
|
|
258
|
-
key,
|
|
259
|
-
val: encodeOptionU32(args.oracleParams?.maxDeviationBps),
|
|
260
|
-
}));
|
|
261
|
-
break;
|
|
262
|
-
case 'oracle_max_xfeed_dev_bps':
|
|
263
|
-
entries.push(new stellar_sdk_1.xdr.ScMapEntry({
|
|
264
|
-
key,
|
|
265
|
-
val: encodeOptionU32(args.oracleParams?.maxCrossFeedDeviationBps),
|
|
266
|
-
}));
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
227
|
+
// Per-field value encoders. Each entry returns the ScVal to drop into the
|
|
228
|
+
// map; the key symbol comes from the surrounding loop. Adding a field is
|
|
229
|
+
// one row here plus the symbol in POLICY_INSTALL_PARAM_FIELDS.
|
|
230
|
+
const oracleParams = args.oracleParams;
|
|
231
|
+
const valueFor = {
|
|
232
|
+
grammar_version: () => stellar_sdk_1.xdr.ScVal.scvU32(args.grammarVersion ?? exports.DEFAULT_GRAMMAR_VERSION),
|
|
233
|
+
install_nonce: () => stellar_sdk_1.xdr.ScVal.scvU32(args.installNonce),
|
|
234
|
+
predicate: () => stellar_sdk_1.xdr.ScVal.scvBytes(predicate),
|
|
235
|
+
predicate_hash: () => stellar_sdk_1.xdr.ScVal.scvBytes(Buffer.from(args.predicateHash, 'hex')),
|
|
236
|
+
oracle_max_staleness_seconds: () => encodeOptionU32(oracleParams?.maxStalenessSeconds),
|
|
237
|
+
oracle_max_deviation_bps: () => encodeOptionU32(oracleParams?.maxDeviationBps),
|
|
238
|
+
oracle_max_xfeed_dev_bps: () => encodeOptionU32(oracleParams?.maxCrossFeedDeviationBps),
|
|
239
|
+
};
|
|
240
|
+
const entries = POLICY_INSTALL_PARAM_FIELDS.map((k) => new stellar_sdk_1.xdr.ScMapEntry({ key: stellar_sdk_1.xdr.ScVal.scvSymbol(k), val: valueFor[k]() }));
|
|
270
241
|
// The host orders map entries by the SYMBOL STRING, not by XDR bytes. A
|
|
271
242
|
// length prefix in the XDR encoding would otherwise put `amount` before
|
|
272
243
|
// `address` and produce a struct the contract reads differently. Emit the
|
|
@@ -18,11 +18,10 @@ export interface InstallRpcClient {
|
|
|
18
18
|
* `getContractVersion` lookup uses `simulateTransaction` against
|
|
19
19
|
* `contract.call('grammar_version')` and decodes the returned u32.
|
|
20
20
|
*
|
|
21
|
-
* The passphrase is a REQUIRED argument
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* which network it dialled; make it say so. */
|
|
21
|
+
* The passphrase is a REQUIRED argument (not read off the server): `rpc.Server`
|
|
22
|
+
* does not carry one, so reaching for `server.networkPassphrase` returned a
|
|
23
|
+
* non-string and every version probe died with "Invalid passphrase provided to
|
|
24
|
+
* Transaction". The caller knows which network it dialled; make it say so. */
|
|
26
25
|
export declare function rpcClientFromServer(server: rpc.Server, networkPassphrase: string): InstallRpcClient;
|
|
27
26
|
/** Inputs for the install-policy build. */
|
|
28
27
|
export interface BuildInstallPolicyArgs {
|
|
@@ -115,6 +114,14 @@ export interface InstallCallDescribes {
|
|
|
115
114
|
kind: 'external';
|
|
116
115
|
verifier: string;
|
|
117
116
|
}>;
|
|
117
|
+
/** Cross-layer L1: a human-readable note about the OZ any-of-N signer
|
|
118
|
+
* semantic that fires for rules with multiple signers. Present only
|
|
119
|
+
* when `signers.length >= 2` (a single-signer rule is trivially any-of-1,
|
|
120
|
+
* and the note would just add noise). The note is purely additive to
|
|
121
|
+
* the review card text - it does NOT alter the wire bytes or the
|
|
122
|
+
* signer-set constraint, only the description a human reads before
|
|
123
|
+
* signing the install. */
|
|
124
|
+
signerNote: string | null;
|
|
118
125
|
/** One entry per policy attached to the rule, decoded from the policies
|
|
119
126
|
* map (args[4]). The address is the map key; the kind + extras below
|
|
120
127
|
* describe the value. The interpreter policy also reports the
|
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// src/install/build-install-policy.ts - builds the unsigned Soroban
|
|
3
|
-
//
|
|
4
|
-
// `account.remove_context_rule(...)`.
|
|
2
|
+
// src/install/build-install-policy.ts - builds the unsigned Soroban transaction
|
|
3
|
+
// XDR for `account.add_context_rule(...)` and `account.remove_context_rule(...)`.
|
|
5
4
|
//
|
|
6
|
-
// The MCP server is stateless and holds no key material
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
5
|
+
// The MCP server is stateless and holds no key material, so this module NEVER
|
|
6
|
+
// signs. The caller (wallet / CLI / SDK consumer) wraps the returned XDR in a
|
|
7
|
+
// transaction envelope and signs that envelope with their wallet; the wallet
|
|
8
|
+
// signature IS the user-confirmation step.
|
|
10
9
|
//
|
|
11
|
-
// We deliberately depart from the
|
|
10
|
+
// We deliberately depart from the original design, which called for a
|
|
12
11
|
// two-call `install_policy`/`confirm_install` pair backed by a host-signed
|
|
13
|
-
// short-TTL `action_id`. That contract requires
|
|
14
|
-
//
|
|
15
|
-
//
|
|
12
|
+
// short-TTL `action_id`. That contract requires stateful store + key material
|
|
13
|
+
// the server does not have, so we ship the simpler ONE-CALL shape. The wallet
|
|
14
|
+
// signature covers the change.
|
|
16
15
|
//
|
|
17
16
|
// `buildInstallPolicyXdr` installs the policy in ONE call. `add_context_rule`
|
|
18
17
|
// takes `policies` as a `Map<policy_address, install_param>` and the account
|
|
19
18
|
// forwards each install_param to that policy, so the interpreter stores the
|
|
20
|
-
// predicate document as part of this same transaction.
|
|
21
|
-
// documented a second `interpreter.install` call; that was wrong, and issuing
|
|
22
|
-
// it fails - the account re-enters the interpreter while it is mid-install.
|
|
19
|
+
// predicate document as part of this same transaction.
|
|
23
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
21
|
exports.DEFAULT_GRAMMAR_VERSION = exports.Contract = void 0;
|
|
25
22
|
exports.rpcClientFromServer = rpcClientFromServer;
|
|
@@ -35,11 +32,10 @@ const oz_auth_ts_1 = require("./oz-auth.js");
|
|
|
35
32
|
* `getContractVersion` lookup uses `simulateTransaction` against
|
|
36
33
|
* `contract.call('grammar_version')` and decodes the returned u32.
|
|
37
34
|
*
|
|
38
|
-
* The passphrase is a REQUIRED argument
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* which network it dialled; make it say so. */
|
|
35
|
+
* The passphrase is a REQUIRED argument (not read off the server): `rpc.Server`
|
|
36
|
+
* does not carry one, so reaching for `server.networkPassphrase` returned a
|
|
37
|
+
* non-string and every version probe died with "Invalid passphrase provided to
|
|
38
|
+
* Transaction". The caller knows which network it dialled; make it say so. */
|
|
43
39
|
function rpcClientFromServer(server, networkPassphrase) {
|
|
44
40
|
return {
|
|
45
41
|
getAccount: (address) => server.getAccount(address),
|
|
@@ -345,7 +341,7 @@ function decodeInstallCallDescribes(tx, expectedInstallNonce) {
|
|
|
345
341
|
const tag = tuple[0]?.sym().toString();
|
|
346
342
|
const inner = tuple[1];
|
|
347
343
|
if (tag === 'Delegated') {
|
|
348
|
-
if (
|
|
344
|
+
if (inner?.switch().name !== 'scvAddress') {
|
|
349
345
|
throw new Error('install_policy: a Delegated signer is missing its Address');
|
|
350
346
|
}
|
|
351
347
|
signers.push({
|
|
@@ -355,7 +351,7 @@ function decodeInstallCallDescribes(tx, expectedInstallNonce) {
|
|
|
355
351
|
continue;
|
|
356
352
|
}
|
|
357
353
|
if (tag === 'External') {
|
|
358
|
-
if (
|
|
354
|
+
if (inner?.switch().name !== 'scvAddress') {
|
|
359
355
|
throw new Error('install_policy: an External signer is missing its verifier Address');
|
|
360
356
|
}
|
|
361
357
|
signers.push({
|
|
@@ -397,12 +393,12 @@ function decodeInstallCallDescribes(tx, expectedInstallNonce) {
|
|
|
397
393
|
// OZ primitives carry spending_limit/period_ledgers/threshold/signers.
|
|
398
394
|
if (fields.has('predicate') || fields.has('grammar_version') || fields.has('install_nonce')) {
|
|
399
395
|
const installNonceScv = fields.get('install_nonce');
|
|
400
|
-
if (
|
|
396
|
+
if (installNonceScv?.switch().name !== 'scvU32') {
|
|
401
397
|
throw new Error(`install_policy: interpreter policy ${address} is missing a u32 install_nonce`);
|
|
402
398
|
}
|
|
403
399
|
const installNonce = installNonceScv.u32();
|
|
404
400
|
const predicateScv = fields.get('predicate');
|
|
405
|
-
if (
|
|
401
|
+
if (predicateScv?.switch().name !== 'scvBytes') {
|
|
406
402
|
throw new Error(`install_policy: interpreter policy ${address} is missing its bytes predicate`);
|
|
407
403
|
}
|
|
408
404
|
const predicateBytes = Buffer.from(predicateScv.bytes());
|
|
@@ -443,12 +439,25 @@ function decodeInstallCallDescribes(tx, expectedInstallNonce) {
|
|
|
443
439
|
// `observedInstallNonce` is the nonce baked into whichever interpreter
|
|
444
440
|
// policy is present; when none, fall back to the caller-supplied value.
|
|
445
441
|
const installNonce = observedInstallNonce ?? expectedInstallNonce;
|
|
442
|
+
// Cross-layer L1: OZ Accounts context rules follow any-of-N semantics for
|
|
443
|
+
// the signers they accept - any ONE attached signer may authorise a
|
|
444
|
+
// permitted op under the rule. A user with multiple signers attached
|
|
445
|
+
// therefore has a strict superset of authority of a single-signer rule,
|
|
446
|
+
// not a stricter one; the install succeeds as written, but a human
|
|
447
|
+
// reviewing the install card may expect the opposite (and choose the
|
|
448
|
+
// wrong threshold because of it). Surface the any-of-N note on the
|
|
449
|
+
// description so the human reads the same wire-level semantic the
|
|
450
|
+
// contract enforces.
|
|
451
|
+
const signerNote = signers.length >= 2
|
|
452
|
+
? 'any ONE signer may authorise a permitted op under this rule (OZ any-of-N semantic)'
|
|
453
|
+
: null;
|
|
446
454
|
return {
|
|
447
455
|
targetContract,
|
|
448
456
|
fnName: 'add_context_rule',
|
|
449
457
|
ruleName,
|
|
450
458
|
validUntilLedger,
|
|
451
459
|
signers,
|
|
460
|
+
signerNote,
|
|
452
461
|
policies,
|
|
453
462
|
installNonce,
|
|
454
463
|
};
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
// Per design decision 5: phase-04's "audit #44" is aspirational and has no
|
|
11
11
|
// source-of-truth in the repo. Returning a fabricated audit id would be a
|
|
12
12
|
// lie on a security surface. The honest outputs are:
|
|
13
|
-
// - the pinned address (
|
|
13
|
+
// - the pinned address (`PINNED_INTERPRETER_*_ADDRESS` in run/schemas.ts)
|
|
14
14
|
// - the pinned grammar version (SELF_VERSION in version.rs)
|
|
15
|
-
// - the pinned wasm sha256 (
|
|
15
|
+
// - the pinned wasm sha256 (`PINNED_INTERPRETER_WASM_SHA256` in run/schemas.ts)
|
|
16
16
|
// - an OPTIONAL `deployedGrammarVersion` returned by a live `grammar_version()`
|
|
17
17
|
// RPC call, with a `liveMatchesPin` boolean the caller can dispatch on. A
|
|
18
18
|
// mismatch means the deployed wasm is NOT the pinned artifact - the caller
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ADD_CONTEXT_RULE_SYMBOL, type AddContextRuleArgs, type BuildAddContextRuleArgs, buildAddContextRuleArgs, DEFAULT_GRAMMAR_VERSION, } from './build-add-context-rule.ts';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_GRAMMAR_VERSION = exports.buildAddContextRuleArgs = exports.ADD_CONTEXT_RULE_SYMBOL = void 0;
|
|
4
|
+
// Public entry for the install-argument builders.
|
|
5
|
+
//
|
|
6
|
+
// `buildAddContextRuleArgs` is the encoder `runInstallPolicy` uses to turn a
|
|
7
|
+
// ContextRuleDraft into the `add_context_rule` arguments. It was reachable
|
|
8
|
+
// only from inside this package, so a browser client that wants to build the
|
|
9
|
+
// same call had the choice of re-implementing the encoding or going without.
|
|
10
|
+
// Re-implementing it is not a real option: the interpreter compares
|
|
11
|
+
// sha256(context_rule.signers) at enforce time, so an encoding that differs in
|
|
12
|
+
// any field yields a rule that denies every call, and an omitted policy yields
|
|
13
|
+
// one that permits every call. Both failure modes have happened.
|
|
14
|
+
//
|
|
15
|
+
// Exported here rather than from the package root to keep the root surface
|
|
16
|
+
// about synthesis, and because these are transaction-building primitives whose
|
|
17
|
+
// callers should know they are reaching for them.
|
|
18
|
+
var build_add_context_rule_ts_1 = require("./build-add-context-rule.js");
|
|
19
|
+
Object.defineProperty(exports, "ADD_CONTEXT_RULE_SYMBOL", { enumerable: true, get: function () { return build_add_context_rule_ts_1.ADD_CONTEXT_RULE_SYMBOL; } });
|
|
20
|
+
Object.defineProperty(exports, "buildAddContextRuleArgs", { enumerable: true, get: function () { return build_add_context_rule_ts_1.buildAddContextRuleArgs; } });
|
|
21
|
+
Object.defineProperty(exports, "DEFAULT_GRAMMAR_VERSION", { enumerable: true, get: function () { return build_add_context_rule_ts_1.DEFAULT_GRAMMAR_VERSION; } });
|
|
@@ -39,9 +39,11 @@ const u32 = (n) => stellar_sdk_1.xdr.ScVal.scvU32(n);
|
|
|
39
39
|
const vec = (i) => stellar_sdk_1.xdr.ScVal.scvVec(i);
|
|
40
40
|
const bytes = (b) => stellar_sdk_1.xdr.ScVal.scvBytes(b);
|
|
41
41
|
function struct(fields) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
// Entries sorted by key with the default string comparison - ScMap
|
|
43
|
+
// encoding requires the same order Object.keys().sort() produced.
|
|
44
|
+
return stellar_sdk_1.xdr.ScVal.scvMap(Object.entries(fields)
|
|
45
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
46
|
+
.map(([k, v]) => new stellar_sdk_1.xdr.ScMapEntry({ key: sym(k), val: v })));
|
|
45
47
|
}
|
|
46
48
|
/** `Signer::Delegated(addr)`. */
|
|
47
49
|
const delegatedSigner = (a) => vec([sym('Delegated'), new stellar_sdk_1.Address(a).toScVal()]);
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// this module takes it from there.
|
|
9
9
|
//
|
|
10
10
|
// Mirrors `decode_leaf` / `decode_node` in
|
|
11
|
-
// `
|
|
11
|
+
// `contracts/policy-interpreter/src/dsl.rs`. Two rules carry most of the
|
|
12
12
|
// weight, and both come from the Rust decoder verbatim:
|
|
13
13
|
//
|
|
14
14
|
// 1. A `Vec` whose FIRST element is a Symbol is a selector tuple. A `Vec`
|