@under18dev/veritas-solver-z3 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,13 @@
1
- # Temporary Holding Version
1
+ # @under18dev/veritas-solver-z3
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ SMT-LIB generation and Z3 execution for Veritas
4
+
5
+ Part of [Veritas](https://github.com/under18dev/veritas), specification-aware test verification for TypeScript/JavaScript projects. Most users install the main package, which provides the `veritas` and `veritas-mcp` commands and the Node API:
6
+
7
+ ```bash
8
+ npm install -D @under18dev/veritas
9
+ ```
10
+
11
+ This package is an internal building block of that package; its API may change between minor versions. Source: [`packages/solver-z3`](https://github.com/under18dev/veritas/tree/main/packages/solver-z3).
12
+
13
+ Licensed under Apache-2.0.
@@ -0,0 +1,4 @@
1
+ export * from './sexpr.js';
2
+ export * from './smtlib.js';
3
+ export * from './solver.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './sexpr.js';
2
+ export * from './smtlib.js';
3
+ export * from './solver.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type SExpr = string | SExpr[];
2
+ /** Minimal S-expression reader for solver output (atoms, lists, quoted symbols and strings). */
3
+ export declare function parseSExprs(text: string): SExpr[];
4
+ /** Convert a model value (`5`, `(- 5)`, `true`) to a decimal string or boolean. */
5
+ export declare function modelValue(value: SExpr): string | boolean;
6
+ export declare function parseGetValue(list: SExpr): Record<string, string | boolean>;
7
+ //# sourceMappingURL=sexpr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sexpr.d.ts","sourceRoot":"","sources":["../src/sexpr.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,KAAK,EAAE,CAAC;AAErC,gGAAgG;AAChG,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,CA0BjD;AAID,mFAAmF;AACnF,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAiBzD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAW3E"}
package/dist/sexpr.js ADDED
@@ -0,0 +1,56 @@
1
+ /** Minimal S-expression reader for solver output (atoms, lists, quoted symbols and strings). */
2
+ export function parseSExprs(text) {
3
+ const tokens = text.match(/\(|\)|"(?:[^"]|"")*"|\|[^|]*\||[^\s()"|]+/g) ?? [];
4
+ let i = 0;
5
+ const read = () => {
6
+ const token = tokens[i++];
7
+ if (token === undefined)
8
+ throw new Error('unexpected end of solver output');
9
+ if (token === ')')
10
+ throw new Error('unexpected ) in solver output');
11
+ if (token !== '(')
12
+ return token;
13
+ const list = [];
14
+ while (tokens[i] !== ')') {
15
+ if (i >= tokens.length)
16
+ throw new Error('unbalanced ( in solver output');
17
+ list.push(read());
18
+ }
19
+ i++;
20
+ return list;
21
+ };
22
+ const out = [];
23
+ while (i < tokens.length)
24
+ out.push(read());
25
+ return out;
26
+ }
27
+ const unquote = (s) => (s.startsWith('|') && s.endsWith('|') ? s.slice(1, -1) : s);
28
+ /** Convert a model value (`5`, `(- 5)`, `true`) to a decimal string or boolean. */
29
+ export function modelValue(value) {
30
+ if (value === 'true')
31
+ return true;
32
+ if (value === 'false')
33
+ return false;
34
+ if (typeof value === 'string' && /^\d+$/.test(value))
35
+ return value;
36
+ if (Array.isArray(value) &&
37
+ value.length === 2 &&
38
+ value[0] === '-' &&
39
+ typeof value[1] === 'string' &&
40
+ /^\d+$/.test(value[1])) {
41
+ return `-${value[1]}`;
42
+ }
43
+ throw new Error(`unsupported model value: ${JSON.stringify(value)}`);
44
+ }
45
+ export function parseGetValue(list) {
46
+ if (!Array.isArray(list))
47
+ throw new Error('get-value output is not a list');
48
+ const out = {};
49
+ for (const pair of list) {
50
+ if (!Array.isArray(pair) || pair.length !== 2 || typeof pair[0] !== 'string')
51
+ throw new Error('malformed get-value pair');
52
+ out[unquote(pair[0])] = modelValue(pair[1]);
53
+ }
54
+ return out;
55
+ }
56
+ //# sourceMappingURL=sexpr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sexpr.js","sourceRoot":"","sources":["../src/sexpr.ts"],"names":[],"mappings":"AAEA,gGAAgG;AAChG,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,4CAA4C,CAAC,IAAI,EAAE,CAAC;IAC9E,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,MAAM,IAAI,GAAG,GAAU,EAAE;QACvB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;QAE1B,IAAI,KAAK,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QAE5E,IAAI,KAAK,KAAK,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QAEpE,IAAI,KAAK,KAAK,GAAG;YAAE,OAAO,KAAK,CAAC;QAChC,MAAM,IAAI,GAAY,EAAE,CAAC;QAEz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CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAW;IACvC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAC5E,MAAM,GAAG,GAAqC,EAAE,CAAC;IAEjD,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;YAC1E,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAU,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { type Expr, type FunctionModel, type PropertyIR, type Sort } from '@under18dev/veritas-core';
2
+ export declare const SAFE_MAX = 9007199254740991n;
3
+ export declare const SAFE_MIN = -9007199254740991n;
4
+ type Env = Map<string, Sort>;
5
+ /** Infer the sort of an expression, rejecting ill-sorted IR instead of letting the solver guess. */
6
+ export declare function sortOf(expr: Expr, env: Env, functions: Map<string, FunctionModel>): Sort;
7
+ export declare function emitExpr(expr: Expr): string;
8
+ /** Validate an IR document: names, sorts, domains inside the safe-integer range, no recursion. */
9
+ export declare function checkIR(ir: PropertyIR): void;
10
+ /**
11
+ * Query for "forall params in their domains: preconditions => body".
12
+ * `unsat` means no counterexample exists in the model; `sat` yields one.
13
+ */
14
+ export declare function conformanceQuery(ir: PropertyIR, timeoutMs: number): string;
15
+ /**
16
+ * Query for the JS-number obligation: can any intermediate integer leave the safe-integer range for an
17
+ * input in the domain? `unsat` means integer arithmetic and JS doubles agree on every reachable input.
18
+ * Returns null when the property has no arithmetic.
19
+ */
20
+ export declare function safeRangeQuery(ir: PropertyIR, timeoutMs: number): string | null;
21
+ export {};
22
+ //# sourceMappingURL=smtlib.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smtlib.d.ts","sourceRoot":"","sources":["../src/smtlib.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,EACT,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,IAAI,EAEV,MAAM,0BAA0B,CAAC;AAElC,eAAO,MAAM,QAAQ,oBAAoB,CAAC;AAC1C,eAAO,MAAM,QAAQ,qBAAqB,CAAC;AAiC3C,KAAK,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAE7B,oGAAoG;AACpG,wBAAgB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,IAAI,CAuExF;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAqB3C;AA0CD,kGAAkG;AAClG,wBAAgB,OAAO,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI,CA+C5C;AA0CD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAU1E;AA4DD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAqB/E"}
package/dist/smtlib.js ADDED
@@ -0,0 +1,320 @@
1
+ import { VeritasError, } from '@under18dev/veritas-core';
2
+ export const SAFE_MAX = 9007199254740991n;
3
+ export const SAFE_MIN = -9007199254740991n;
4
+ const NAME = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
5
+ function symbol(name) {
6
+ if (!NAME.test(name))
7
+ throw new VeritasError('user', 'IR_INVALID_NAME', `invalid identifier in property IR: ${name}`);
8
+ return `|${name}|`;
9
+ }
10
+ function intLiteral(value) {
11
+ const v = BigInt(value);
12
+ return v < 0n ? `(- ${-v})` : `${v}`;
13
+ }
14
+ const SMT_OP = {
15
+ '+': '+',
16
+ '-': '-',
17
+ '*': '*',
18
+ div: 'div',
19
+ mod: 'mod',
20
+ '<': '<',
21
+ '<=': '<=',
22
+ '>': '>',
23
+ '>=': '>=',
24
+ '==': '=',
25
+ and: 'and',
26
+ or: 'or',
27
+ implies: '=>',
28
+ };
29
+ /** Infer the sort of an expression, rejecting ill-sorted IR instead of letting the solver guess. */
30
+ export function sortOf(expr, env, functions) {
31
+ const fail = (message) => {
32
+ throw new VeritasError('user', 'IR_ILL_SORTED', message);
33
+ };
34
+ switch (expr.kind) {
35
+ case 'var': {
36
+ const s = env.get(expr.name);
37
+ return s ?? fail(`unbound variable ${expr.name}`);
38
+ }
39
+ case 'int':
40
+ return 'int';
41
+ case 'bool':
42
+ return 'bool';
43
+ case 'unary': {
44
+ const s = sortOf(expr.arg, env, functions);
45
+ if (expr.op === 'not' && s !== 'bool')
46
+ fail('`not` expects bool');
47
+ if (expr.op === 'neg' && s !== 'int')
48
+ fail('`neg` expects int');
49
+ return s;
50
+ }
51
+ case 'binary': {
52
+ const l = sortOf(expr.left, env, functions);
53
+ const r = sortOf(expr.right, env, functions);
54
+ if (['+', '-', '*', 'div', 'mod'].includes(expr.op)) {
55
+ if (l !== 'int' || r !== 'int')
56
+ fail(`${expr.op} expects int operands`);
57
+ return 'int';
58
+ }
59
+ if (['<', '<=', '>', '>='].includes(expr.op)) {
60
+ if (l !== 'int' || r !== 'int')
61
+ fail(`${expr.op} expects int operands`);
62
+ return 'bool';
63
+ }
64
+ if (expr.op === '==' || expr.op === '!=') {
65
+ if (l !== r)
66
+ fail(`${expr.op} compares ${l} with ${r}`);
67
+ return 'bool';
68
+ }
69
+ if (l !== 'bool' || r !== 'bool')
70
+ fail(`${expr.op} expects bool operands`);
71
+ return 'bool';
72
+ }
73
+ case 'ite': {
74
+ if (sortOf(expr.cond, env, functions) !== 'bool')
75
+ fail('ite condition must be bool');
76
+ const a = sortOf(expr.whenTrue, env, functions);
77
+ const b = sortOf(expr.whenFalse, env, functions);
78
+ if (a !== b)
79
+ fail('ite branches have different sorts');
80
+ return a;
81
+ }
82
+ case 'call': {
83
+ const fn = functions.get(expr.fn) ?? fail(`unknown function ${expr.fn}`);
84
+ if (fn.params.length !== expr.args.length)
85
+ fail(`${expr.fn} expects ${fn.params.length} arguments`);
86
+ expr.args.forEach((arg, i) => {
87
+ if (sortOf(arg, env, functions) !== fn.params[i]?.sort)
88
+ fail(`argument ${i + 1} of ${expr.fn} has the wrong sort`);
89
+ });
90
+ return fn.returns;
91
+ }
92
+ }
93
+ }
94
+ export function emitExpr(expr) {
95
+ switch (expr.kind) {
96
+ case 'var':
97
+ return symbol(expr.name);
98
+ case 'int':
99
+ return intLiteral(expr.value);
100
+ case 'bool':
101
+ return expr.value ? 'true' : 'false';
102
+ case 'unary':
103
+ return expr.op === 'not' ? `(not ${emitExpr(expr.arg)})` : `(- ${emitExpr(expr.arg)})`;
104
+ case 'binary':
105
+ if (expr.op === '!=')
106
+ return `(not (= ${emitExpr(expr.left)} ${emitExpr(expr.right)}))`;
107
+ return `(${SMT_OP[expr.op]} ${emitExpr(expr.left)} ${emitExpr(expr.right)})`;
108
+ case 'ite':
109
+ return `(ite ${emitExpr(expr.cond)} ${emitExpr(expr.whenTrue)} ${emitExpr(expr.whenFalse)})`;
110
+ case 'call':
111
+ return expr.args.length === 0
112
+ ? symbol(expr.fn)
113
+ : `(${symbol(expr.fn)} ${expr.args.map(emitExpr).join(' ')})`;
114
+ }
115
+ }
116
+ const SMT_SORT = { int: 'Int', bool: 'Bool' };
117
+ /** Functions in dependency order; recursion is outside the supported subset. */
118
+ function orderFunctions(functions) {
119
+ const byName = new Map(functions.map((f) => [f.name, f]));
120
+ const ordered = [];
121
+ const state = new Map();
122
+ const visit = (f) => {
123
+ if (state.get(f.name) === 'done')
124
+ return;
125
+ if (state.get(f.name) === 'visiting') {
126
+ throw new VeritasError('user', 'IR_RECURSIVE', `recursive function ${f.name} is not supported`);
127
+ }
128
+ state.set(f.name, 'visiting');
129
+ const walk = (e) => {
130
+ if (e.kind === 'call') {
131
+ const callee = byName.get(e.fn);
132
+ if (callee)
133
+ visit(callee);
134
+ e.args.forEach(walk);
135
+ }
136
+ else if (e.kind === 'unary')
137
+ walk(e.arg);
138
+ else if (e.kind === 'binary') {
139
+ walk(e.left);
140
+ walk(e.right);
141
+ }
142
+ else if (e.kind === 'ite') {
143
+ walk(e.cond);
144
+ walk(e.whenTrue);
145
+ walk(e.whenFalse);
146
+ }
147
+ };
148
+ if (f.body)
149
+ walk(f.body);
150
+ state.set(f.name, 'done');
151
+ ordered.push(f);
152
+ };
153
+ functions.forEach(visit);
154
+ return ordered;
155
+ }
156
+ /** Validate an IR document: names, sorts, domains inside the safe-integer range, no recursion. */
157
+ export function checkIR(ir) {
158
+ const functions = new Map();
159
+ for (const f of ir.functions) {
160
+ symbol(f.name);
161
+ if (functions.has(f.name))
162
+ throw new VeritasError('user', 'IR_DUPLICATE', `duplicate function ${f.name}`);
163
+ functions.set(f.name, f);
164
+ }
165
+ orderFunctions(ir.functions);
166
+ for (const f of ir.functions) {
167
+ if (!f.body)
168
+ continue;
169
+ const env = new Map(f.params.map((p) => [p.name, p.sort]));
170
+ if (sortOf(f.body, env, functions) !== f.returns) {
171
+ throw new VeritasError('user', 'IR_ILL_SORTED', `body of ${f.name} does not return ${f.returns}`);
172
+ }
173
+ }
174
+ const env = new Map();
175
+ for (const p of ir.params) {
176
+ symbol(p.name);
177
+ if (env.has(p.name))
178
+ throw new VeritasError('user', 'IR_DUPLICATE', `duplicate parameter ${p.name}`);
179
+ env.set(p.name, p.sort);
180
+ if (p.sort === 'int' && (BigInt(p.domain.min) < SAFE_MIN || BigInt(p.domain.max) > SAFE_MAX)) {
181
+ throw new VeritasError('user', 'IR_DOMAIN_UNSAFE', `domain of ${p.name} exceeds the safe-integer range`);
182
+ }
183
+ // An empty domain makes every property vacuously unsat.
184
+ if (p.sort === 'int' && BigInt(p.domain.min) > BigInt(p.domain.max)) {
185
+ throw new VeritasError('user', 'IR_DOMAIN_EMPTY', `domain of ${p.name} is empty (min > max)`);
186
+ }
187
+ }
188
+ for (const pre of ir.preconditions) {
189
+ if (sortOf(pre, env, functions) !== 'bool')
190
+ throw new VeritasError('user', 'IR_ILL_SORTED', 'precondition must be bool');
191
+ }
192
+ if (sortOf(ir.body, env, functions) !== 'bool')
193
+ throw new VeritasError('user', 'IR_ILL_SORTED', 'property body must be bool');
194
+ }
195
+ function preamble(ir, timeoutMs) {
196
+ const lines = [
197
+ '(set-logic ALL)',
198
+ `(set-option :timeout ${timeoutMs})`,
199
+ '(set-option :produce-models true)',
200
+ ];
201
+ for (const f of orderFunctions(ir.functions)) {
202
+ const params = f.params.map((p) => `(${symbol(p.name)} ${SMT_SORT[p.sort]})`).join(' ');
203
+ if (f.body)
204
+ lines.push(`(define-fun ${symbol(f.name)} (${params}) ${SMT_SORT[f.returns]} ${emitExpr(f.body)})`);
205
+ else
206
+ lines.push(`(declare-fun ${symbol(f.name)} (${f.params.map((p) => SMT_SORT[p.sort]).join(' ')}) ${SMT_SORT[f.returns]})`);
207
+ }
208
+ for (const p of ir.params) {
209
+ lines.push(`(declare-const ${symbol(p.name)} ${SMT_SORT[p.sort]})`);
210
+ if (p.sort === 'int') {
211
+ lines.push(`(assert (<= ${intLiteral(p.domain.min)} ${symbol(p.name)} ${intLiteral(p.domain.max)}))`);
212
+ }
213
+ }
214
+ for (const pre of ir.preconditions)
215
+ lines.push(`(assert ${emitExpr(pre)})`);
216
+ return lines;
217
+ }
218
+ function epilogue(ir) {
219
+ const out = ['(check-sat)'];
220
+ if (ir.params.length > 0)
221
+ out.push(`(get-value (${ir.params.map((p) => symbol(p.name)).join(' ')}))`);
222
+ out.push('(get-info :reason-unknown)');
223
+ return out;
224
+ }
225
+ /**
226
+ * Query for "forall params in their domains: preconditions => body".
227
+ * `unsat` means no counterexample exists in the model; `sat` yields one.
228
+ */
229
+ export function conformanceQuery(ir, timeoutMs) {
230
+ checkIR(ir);
231
+ return [
232
+ '; veritas conformance query: is there an input in the domain that violates the property?',
233
+ ...preamble(ir, timeoutMs),
234
+ `(assert (not ${emitExpr(ir.body)}))`,
235
+ ...epilogue(ir),
236
+ '',
237
+ ].join('\n');
238
+ }
239
+ /** Replace calls with function bodies so every arithmetic term is expressed over the property parameters. */
240
+ function inline(expr, functions, subst = new Map()) {
241
+ switch (expr.kind) {
242
+ case 'var':
243
+ return subst.get(expr.name) ?? expr;
244
+ case 'int':
245
+ case 'bool':
246
+ return expr;
247
+ case 'unary':
248
+ return { ...expr, arg: inline(expr.arg, functions, subst) };
249
+ case 'binary':
250
+ return {
251
+ ...expr,
252
+ left: inline(expr.left, functions, subst),
253
+ right: inline(expr.right, functions, subst),
254
+ };
255
+ case 'ite':
256
+ return {
257
+ ...expr,
258
+ cond: inline(expr.cond, functions, subst),
259
+ whenTrue: inline(expr.whenTrue, functions, subst),
260
+ whenFalse: inline(expr.whenFalse, functions, subst),
261
+ };
262
+ case 'call': {
263
+ const fn = functions.get(expr.fn);
264
+ const args = expr.args.map((a) => inline(a, functions, subst));
265
+ if (!fn?.body)
266
+ return { ...expr, args };
267
+ const inner = new Map(fn.params.map((p, i) => [p.name, args[i]]));
268
+ return inline(fn.body, functions, inner);
269
+ }
270
+ }
271
+ }
272
+ function arithmeticTerms(expr, out = []) {
273
+ if (expr.kind === 'binary') {
274
+ if (['+', '-', '*'].includes(expr.op))
275
+ out.push(expr);
276
+ arithmeticTerms(expr.left, out);
277
+ arithmeticTerms(expr.right, out);
278
+ }
279
+ else if (expr.kind === 'unary') {
280
+ if (expr.op === 'neg')
281
+ out.push(expr);
282
+ arithmeticTerms(expr.arg, out);
283
+ }
284
+ else if (expr.kind === 'ite') {
285
+ arithmeticTerms(expr.cond, out);
286
+ arithmeticTerms(expr.whenTrue, out);
287
+ arithmeticTerms(expr.whenFalse, out);
288
+ }
289
+ else if (expr.kind === 'call') {
290
+ for (const a of expr.args)
291
+ arithmeticTerms(a, out);
292
+ }
293
+ return out;
294
+ }
295
+ /**
296
+ * Query for the JS-number obligation: can any intermediate integer leave the safe-integer range for an
297
+ * input in the domain? `unsat` means integer arithmetic and JS doubles agree on every reachable input.
298
+ * Returns null when the property has no arithmetic.
299
+ */
300
+ export function safeRangeQuery(ir, timeoutMs) {
301
+ checkIR(ir);
302
+ const functions = new Map(ir.functions.map((f) => [f.name, f]));
303
+ const terms = arithmeticTerms(inline(ir.body, functions));
304
+ for (const pre of ir.preconditions)
305
+ terms.push(...arithmeticTerms(inline(pre, functions)));
306
+ if (terms.length === 0)
307
+ return null;
308
+ const outOfRange = terms.map((t) => {
309
+ const e = emitExpr(t);
310
+ return `(or (< ${e} ${intLiteral(SAFE_MIN)}) (> ${e} ${intLiteral(SAFE_MAX)}))`;
311
+ });
312
+ return [
313
+ '; veritas safe-integer obligation: can an intermediate value leave the JS safe-integer range?',
314
+ ...preamble(ir, timeoutMs),
315
+ `(assert (or ${outOfRange.join(' ')}))`,
316
+ ...epilogue(ir),
317
+ '',
318
+ ].join('\n');
319
+ }
320
+ //# sourceMappingURL=smtlib.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smtlib.js","sourceRoot":"","sources":["../src/smtlib.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,YAAY,GACb,MAAM,0BAA0B,CAAC;AAElC,MAAM,CAAC,MAAM,QAAQ,GAAG,iBAAiB,CAAC;AAC1C,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,iBAAiB,CAAC;AAE3C,MAAM,IAAI,GAAG,4BAA4B,CAAC;AAE1C,SAAS,MAAM,CAAC,IAAY;I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,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,MAAM,KAAK,GAAG,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAE1D,KAAK,MAAM,GAAG,IAAI,EAAE,CAAC,aAAa;QAAE,KAAK,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAE3F,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACpC,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACjC,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QAEtB,OAAO,UAAU,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC;IAClF,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,+FAA+F;QAC/F,GAAG,QAAQ,CAAC,EAAE,EAAE,SAAS,CAAC;QAC1B,eAAe,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI;QACvC,GAAG,QAAQ,CAAC,EAAE,CAAC;QACf,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
@@ -0,0 +1,43 @@
1
+ export type SolverEngine = 'z3-wasm' | 'z3-native';
2
+ export type SolverVerdict = 'sat' | 'unsat' | 'unknown' | 'timeout' | 'error' | 'cancelled';
3
+ export interface SolverRun {
4
+ engine: SolverEngine;
5
+ engineVersion: string;
6
+ verdict: SolverVerdict;
7
+ /** Assignment for `sat` results; empty otherwise. */
8
+ model: Record<string, string | boolean>;
9
+ reasonUnknown: string | null;
10
+ output: string;
11
+ error: string | null;
12
+ durationMs: number;
13
+ }
14
+ export interface SolveOptions {
15
+ engine?: SolverEngine;
16
+ /** Hard wall-clock limit. The SMT input should also carry a soft `:timeout`. */
17
+ timeoutMs: number;
18
+ signal?: AbortSignal;
19
+ nativeBinary?: string;
20
+ /**
21
+ * Memory limit in MiB, defaulting to the run's `limits.memoryMb`: the JavaScript heap of the WebAssembly solver
22
+ * process, or z3's own `-memory:` limit for the native binary.
23
+ */
24
+ memoryMb?: number;
25
+ /** Test hook: the script the WebAssembly solver process runs (default: the bundled `wasm-worker`). */
26
+ wasmScript?: string;
27
+ }
28
+ /**
29
+ * Interpret raw solver output strictly. Only a first line of exactly `sat`, `unsat` or `unknown` is accepted;
30
+ * anything else is `error`. An `unknown` with reason `timeout`/`canceled` becomes `timeout`.
31
+ */
32
+ export declare function interpretOutput(output: string): Pick<SolverRun, 'verdict' | 'model' | 'reasonUnknown' | 'error'>;
33
+ /** Below this the solver process cannot even start Z3. */
34
+ export declare const MIN_SOLVER_HEAP_MB = 256;
35
+ /** The solver process heap limit for a requested limit: never below `MIN_SOLVER_HEAP_MB`; undefined means no limit. */
36
+ export declare function solverHeapLimit(memoryMb: number | undefined): number | undefined;
37
+ /** Arguments of the native z3 binary: SMT-LIB on stdin, and z3's own memory limit (MiB) when one is set. */
38
+ export declare function nativeZ3Args(memoryMb: number | undefined): string[];
39
+ /** Run an SMT-LIB 2 script through Z3. Never infers a verdict that the solver did not print. */
40
+ export declare function solveSmtLib(smt: string, options: SolveOptions): Promise<SolverRun>;
41
+ /** Version of the solver build `engine` would run, or null when it cannot be determined. */
42
+ export declare function solverEngineVersion(engine?: SolverEngine, nativeBinary?: string): Promise<string | null>;
43
+ //# sourceMappingURL=solver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solver.d.ts","sourceRoot":"","sources":["../src/solver.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,WAA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AAG,OAAO,CAAC,SAAS,CAAC,CAElF;AAED,4FAA4F;AAC5F,wBAAsB,mBAAmB,CACvC,MAAM,GAAE,YAAwB,EAChC,YAAY,SAAO,GAClB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAaxB"}
package/dist/solver.js ADDED
@@ -0,0 +1,171 @@
1
+ import { createRequire } from 'node:module';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { outOfMemory, runCommand, runContext } from '@under18dev/veritas-core';
4
+ import { parseGetValue, parseSExprs } from './sexpr.js';
5
+ /**
6
+ * Interpret raw solver output strictly. Only a first line of exactly `sat`, `unsat` or `unknown` is accepted;
7
+ * anything else is `error`. An `unknown` with reason `timeout`/`canceled` becomes `timeout`.
8
+ */
9
+ export function interpretOutput(output) {
10
+ let exprs;
11
+ try {
12
+ exprs = parseSExprs(output);
13
+ }
14
+ catch (error) {
15
+ return {
16
+ verdict: 'error',
17
+ model: {},
18
+ reasonUnknown: null,
19
+ error: `unparsable solver output: ${error.message}`,
20
+ };
21
+ }
22
+ const head = exprs[0];
23
+ // `(get-value ...)` after unsat/unknown legitimately fails with "model is not available"; any other error is fatal.
24
+ const solverError = exprs.find((e) => Array.isArray(e) &&
25
+ e[0] === 'error' &&
26
+ !(head !== 'sat' && typeof e[1] === 'string' && /model is not available/.test(e[1])));
27
+ if (head !== 'sat' && head !== 'unsat' && head !== 'unknown') {
28
+ return {
29
+ verdict: 'error',
30
+ model: {},
31
+ reasonUnknown: null,
32
+ error: `unexpected solver output: ${output.slice(0, 300)}`,
33
+ };
34
+ }
35
+ if (solverError) {
36
+ return {
37
+ verdict: 'error',
38
+ model: {},
39
+ reasonUnknown: null,
40
+ error: `solver reported: ${JSON.stringify(solverError)}`,
41
+ };
42
+ }
43
+ const reasonExpr = exprs.find((e) => Array.isArray(e) && e[0] === ':reason-unknown');
44
+ const reasonUnknown = Array.isArray(reasonExpr) && typeof reasonExpr[1] === 'string'
45
+ ? reasonExpr[1].replace(/^"|"$/g, '')
46
+ : null;
47
+ if (head === 'unknown') {
48
+ const timedOut = reasonUnknown !== null && /timeout|canceled|cancelled|resource/i.test(reasonUnknown);
49
+ return { verdict: timedOut ? 'timeout' : 'unknown', model: {}, reasonUnknown, error: null };
50
+ }
51
+ if (head === 'unsat')
52
+ return { verdict: 'unsat', model: {}, reasonUnknown: null, error: null };
53
+ const valueList = exprs.slice(1).find((e) => Array.isArray(e) && Array.isArray(e[0]));
54
+ try {
55
+ return {
56
+ verdict: 'sat',
57
+ model: valueList ? parseGetValue(valueList) : {},
58
+ reasonUnknown: null,
59
+ error: null,
60
+ };
61
+ }
62
+ catch (error) {
63
+ return {
64
+ verdict: 'error',
65
+ model: {},
66
+ reasonUnknown: null,
67
+ error: `cannot read model: ${error.message}`,
68
+ };
69
+ }
70
+ }
71
+ /** Below this the solver process cannot even start Z3. */
72
+ export const MIN_SOLVER_HEAP_MB = 256;
73
+ /** The solver process heap limit for a requested limit: never below `MIN_SOLVER_HEAP_MB`; undefined means no limit. */
74
+ export function solverHeapLimit(memoryMb) {
75
+ return memoryMb === undefined ? undefined : Math.max(MIN_SOLVER_HEAP_MB, Math.floor(memoryMb));
76
+ }
77
+ async function runWasm(smt, options) {
78
+ // Run next to this module; under tests this module is TypeScript, which Node 24+ runs natively.
79
+ const ext = import.meta.url.endsWith('.ts') ? '.ts' : '.js';
80
+ const script = options.wasmScript ?? fileURLToPath(new URL(`./wasm-worker${ext}`, import.meta.url));
81
+ // The solver process's JavaScript heap is capped at the run's memory limit (Z3's WebAssembly memory is separate
82
+ // and bounded by the 32-bit address space); running out ends that process with an error, never a verdict.
83
+ const memoryMb = solverHeapLimit(options.memoryMb ?? runContext()?.memoryMb);
84
+ const result = await runCommand(process.execPath, [...(memoryMb ? [`--max-old-space-size=${memoryMb}`] : []), script], { cwd: process.cwd(), timeoutMs: options.timeoutMs, input: smt, signal: options.signal });
85
+ const base = {
86
+ engine: 'z3-wasm',
87
+ engineVersion: 'unknown',
88
+ model: {},
89
+ reasonUnknown: null,
90
+ output: '',
91
+ durationMs: result.durationMs,
92
+ };
93
+ if (result.spawnError)
94
+ return { ...base, verdict: 'error', error: result.spawnError };
95
+ if (result.timedOut)
96
+ return { ...base, verdict: 'timeout', error: `wall-clock limit of ${options.timeoutMs} ms exceeded` };
97
+ if (options.signal?.aborted)
98
+ return { ...base, verdict: 'cancelled', error: 'cancelled' };
99
+ const line = result.stdout.trim().split('\n').pop() ?? '';
100
+ let message;
101
+ try {
102
+ message = JSON.parse(line);
103
+ }
104
+ catch {
105
+ message = undefined;
106
+ }
107
+ if (!message || result.exitCode !== 0) {
108
+ const reason = outOfMemory(result.stderr)
109
+ ? `solver ran out of memory (limit ${memoryMb} MiB, limits.memoryMb)`
110
+ : `solver process ended with ${result.signal ? `signal ${result.signal}` : `exit code ${result.exitCode}`}${message?.error ? `: ${message.error}` : ''}`;
111
+ return { ...base, verdict: 'error', error: reason };
112
+ }
113
+ if (!message.ok)
114
+ return { ...base, verdict: 'error', error: message.error ?? 'solver failed' };
115
+ const output = message.output ?? '';
116
+ return { ...base, ...interpretOutput(output), engineVersion: message.version ?? 'unknown', output };
117
+ }
118
+ /** Arguments of the native z3 binary: SMT-LIB on stdin, and z3's own memory limit (MiB) when one is set. */
119
+ export function nativeZ3Args(memoryMb) {
120
+ return ['-in', '-smt2', ...(memoryMb ? [`-memory:${Math.floor(memoryMb)}`] : [])];
121
+ }
122
+ async function runNative(smt, options) {
123
+ const binary = options.nativeBinary ?? 'z3';
124
+ const version = await runCommand(binary, ['--version'], { cwd: process.cwd(), timeoutMs: 10_000 });
125
+ const engineVersion = version.exitCode === 0 ? version.stdout.trim() : 'unknown';
126
+ const result = await runCommand(binary, nativeZ3Args(options.memoryMb ?? runContext()?.memoryMb), {
127
+ cwd: process.cwd(),
128
+ timeoutMs: options.timeoutMs,
129
+ input: smt,
130
+ signal: options.signal,
131
+ });
132
+ const base = {
133
+ engine: 'z3-native',
134
+ engineVersion,
135
+ output: result.stdout,
136
+ durationMs: result.durationMs,
137
+ };
138
+ if (result.spawnError)
139
+ return { ...base, verdict: 'error', model: {}, reasonUnknown: null, error: result.spawnError };
140
+ if (result.timedOut) {
141
+ return {
142
+ ...base,
143
+ verdict: 'timeout',
144
+ model: {},
145
+ reasonUnknown: null,
146
+ error: `wall-clock limit of ${options.timeoutMs} ms exceeded`,
147
+ };
148
+ }
149
+ if (options.signal?.aborted)
150
+ return { ...base, verdict: 'cancelled', model: {}, reasonUnknown: null, error: 'cancelled' };
151
+ return { ...base, ...interpretOutput(result.stdout) };
152
+ }
153
+ /** Run an SMT-LIB 2 script through Z3. Never infers a verdict that the solver did not print. */
154
+ export function solveSmtLib(smt, options) {
155
+ return (options.engine ?? 'z3-wasm') === 'z3-native' ? runNative(smt, options) : runWasm(smt, options);
156
+ }
157
+ /** Version of the solver build `engine` would run, or null when it cannot be determined. */
158
+ export async function solverEngineVersion(engine = 'z3-wasm', nativeBinary = 'z3') {
159
+ if (engine === 'z3-wasm') {
160
+ try {
161
+ const pkg = createRequire(import.meta.url)('z3-solver/package.json');
162
+ return pkg.version ? `z3-solver ${pkg.version}` : null;
163
+ }
164
+ catch {
165
+ return null;
166
+ }
167
+ }
168
+ const version = await runCommand(nativeBinary, ['--version'], { cwd: process.cwd(), timeoutMs: 10_000 });
169
+ return version.exitCode === 0 ? version.stdout.trim() || null : null;
170
+ }
171
+ //# sourceMappingURL=solver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solver.js","sourceRoot":"","sources":["../src/solver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,WAAW,EAAc,MAAM,YAAY,CAAC;AAgCpE;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAc;IAEd,I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EAAE,OAAqB;IAC5D,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,SAAS,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACzG,CAAC;AAED,4FAA4F;AAC5F,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,SAAuB,SAAS,EAChC,YAAY,GAAG,IAAI;IAEnB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,wBAAwB,CAAyB,CAAC;YAE7F,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACzD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,YAAY,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;IAEzG,OAAO,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AACvE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=wasm-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm-worker.d.ts","sourceRoot":"","sources":["../src/wasm-worker.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ import { createRequire } from 'node:module';
2
+ const require = createRequire(import.meta.url);
3
+ const readStdin = async () => {
4
+ const chunks = [];
5
+ for await (const chunk of process.stdin)
6
+ chunks.push(chunk);
7
+ return Buffer.concat(chunks).toString('utf8');
8
+ };
9
+ // z3-solver keeps its own threads alive, so the process exits explicitly once the result is written.
10
+ const finish = (result) => process.stdout.write(`${JSON.stringify(result)}\n`, () => process.exit(0));
11
+ try {
12
+ const smt = await readStdin();
13
+ const { init } = require('z3-solver');
14
+ const { Z3 } = await init();
15
+ const cfg = Z3.mk_config();
16
+ const ctx = Z3.mk_context(cfg);
17
+ Z3.del_config(cfg);
18
+ const output = await Z3.eval_smtlib2_string(ctx, smt);
19
+ finish({ ok: true, output, version: Z3.get_full_version() });
20
+ }
21
+ catch (error) {
22
+ finish({ ok: false, error: error.message ?? String(error) });
23
+ }
24
+ //# sourceMappingURL=wasm-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm-worker.js","sourceRoot":"","sources":["../src/wasm-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAc5C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,MAAM,SAAS,GAAG,KAAK,IAAqB,EAAE;IAC5C,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,OAAO,CAAC,KAAK;QAAE,MAAM,CAAC,IAAI,CAAC,KAAe,CAAC,CAAC;IAEtE,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC,CAAC;AAEF,qGAAqG;AACrG,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9G,IAAI,CAAC;IACH,MAAM,GAAG,GAAG,MAAM,SAAS,EAAE,CAAC;IAC9B,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,WAAW,CAAuC,CAAC;IAC5E,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;IAC5B,MAAM,GAAG,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACnB,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACtD,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AAC/D,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAG,KAAe,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAC1E,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "@under18dev/veritas-solver-z3",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "SMT-LIB generation and Z3 execution for Veritas",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/under18dev/veritas.git",
9
+ "directory": "packages/solver-z3"
10
+ },
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "engines": {
22
+ "node": ">=24"
23
+ },
24
+ "dependencies": {
25
+ "@under18dev/veritas-core": "0.1.1",
26
+ "z3-solver": "5.4.1",
27
+ "zod": "4.6.7"
28
+ }
6
29
  }