-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.rs
More file actions
1382 lines (1304 loc) · 53.9 KB
/
Copy pathschema.rs
File metadata and controls
1382 lines (1304 loc) · 53.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: MPL-2.0
// GraphQL schema definitions - wired to ECHIDNA core
use async_graphql::{Context, Enum, Object, Result, SimpleObject};
use echidna::core::{Tactic as CoreTactic, TacticResult as CoreTacticResult, Term};
use echidna::provers::{ProverConfig, ProverFactory, ProverKind as CoreProverKind};
use std::str::FromStr;
use std::time::Instant;
use crate::resolvers::EchidnaContext;
/// Supported theorem provers in ECHIDNA.
//
// Variant names mirror the well-known prover acronyms (PVS, SPASS, TLAPS,
// GLPK, …); keeping them upper-case matches the core `ProverKind` and every
// other place these tools are referenced.
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Clone, Copy, Enum, Eq, PartialEq)]
pub enum ProverKind {
Agda,
Coq,
Lean,
Isabelle,
Z3,
CVC5,
Metamath,
HOLLight,
Mizar,
PVS,
ACL2,
HOL4,
Idris2,
Vampire,
EProver,
SPASS,
AltErgo,
FStar,
Dafny,
Why3,
TLAPS,
Twelf,
Nuprl,
Minlog,
Imandra,
GLPK,
SCIP,
MiniZinc,
Chuffed,
ORTools,
Lean3,
TypedWasm,
SPIN,
CBMC,
SeaHorn,
CaDiCaL,
Kissat,
MiniSat,
NuSMV,
TLC,
Alloy,
Prism,
UPPAAL,
FramaC,
Viper,
Tamarin,
ProVerif,
KeY,
DReal,
ABC,
TypeLL,
KatagoriaVerifier,
TropicalTypeChecker,
ChoreographicTypeChecker,
EpistemicTypeChecker,
EchoTypeChecker,
SessionTypeChecker,
ModalTypeChecker,
QTTTypeChecker,
EffectRowTypeChecker,
DependentTypeChecker,
RefinementTypeChecker,
OrdinaryTypeChecker,
PhantomTypeChecker,
PolymorphicTypeChecker,
ExistentialTypeChecker,
HigherKindedTypeChecker,
RowTypeChecker,
SubtypingTypeChecker,
IntersectionTypeChecker,
UnionTypeChecker,
GradualTypeChecker,
HoareTypeChecker,
IndexedTypeChecker,
LinearTypeChecker,
AffineTypeChecker,
RelevantTypeChecker,
OrderedTypeChecker,
UniquenessTypeChecker,
ImmutableTypeChecker,
CapabilityTypeChecker,
BunchedTypeChecker,
TemporalTypeChecker,
ProvabilityTypeChecker,
ImpureTypeChecker,
CoeffectTypeChecker,
ProbabilisticTypeChecker,
DyadicTypeChecker,
HomotopyTypeChecker,
CubicalTypeChecker,
NominalTypeChecker,
Abella,
Dedukti,
Cameleer,
ACL2s,
IsabelleZF,
Boogie,
Naproche,
Matita,
Arend,
Athena,
LambdaProlog,
Mercury,
Nitpick,
Nunchaku,
CubicalAgda,
Zipperposition,
Prover9,
OpenSmt,
SmtRat,
Rocq,
UppaalStratego,
MizAR,
GPUVerify,
Faial,
Leo3,
Satallax,
Lash,
AgsyHOL,
IProver,
Princess,
Twee,
MetiTarski,
CSI,
AProVE,
GNATprove,
Stainless,
LiquidHaskell,
KeYmaeraX,
Qepcad,
Redlog,
MleanCoP,
IleanCoP,
NanoCoP,
MetTeL2,
ELK,
Konclude,
Storm,
ProB,
EasyCrypt,
CryptoVerif,
}
/// Status of a proof attempt
#[derive(Debug, Clone, Copy, Enum, Eq, PartialEq)]
pub enum ProofStatus {
Pending,
InProgress,
Success,
Failed,
Timeout,
Error,
}
/// Proof state representation
#[derive(Debug, Clone, SimpleObject)]
pub struct ProofState {
pub id: String,
pub prover: ProverKind,
pub goal: String,
pub status: ProofStatus,
pub proof_script: Vec<String>,
pub goals_remaining: i32,
pub time_elapsed: Option<f64>,
pub error_message: Option<String>,
}
/// Tactic representation
#[derive(Debug, Clone, SimpleObject)]
pub struct Tactic {
pub name: String,
pub args: Vec<String>,
pub description: Option<String>,
pub confidence: Option<f64>,
}
/// Prover information
#[derive(Debug, Clone, SimpleObject)]
pub struct ProverInfo {
pub kind: ProverKind,
pub version: String,
pub tier: i32,
pub complexity: i32,
pub available: bool,
}
// =============================================================================
// Types added 2026-06-01 for echidnabot ↔ echidna seam (issue #180).
//
// These mirror the typed taxonomy now surfaced by REST `/api/verify`
// (`outcome`, optional `mode` / `smt_status`) and the suggestion shape
// the echidnabot Julia-ML client expects (`tactic` / `confidence` /
// `explanation`).
// =============================================================================
/// Typed outcome from a verifyProof call.
///
/// Mirrors the `outcome` field on REST `/api/verify` so GraphQL clients
/// can distinguish e.g. `Timeout` from `NoProofFound` without parsing
/// strings. Added 2026-06-01 (issue #180).
#[derive(Debug, Clone, Copy, Enum, Eq, PartialEq)]
pub enum VerifyOutcome {
/// Prover returned a verified proof.
Proved,
/// Prover finished without a proof.
NoProofFound,
/// Input could not be parsed or was empty.
InvalidInput,
/// Prover does not support a feature in the input.
UnsupportedFeature,
/// Prover exhausted its time budget.
Timeout,
/// Premises are mutually inconsistent.
InconsistentPremises,
/// Prover exited with an error.
ProverError,
/// Echidna-side error (FFI / I/O / sandbox).
SystemError,
}
impl VerifyOutcome {
/// Map the REST `outcome: String` representation onto the enum.
pub fn from_rest_str(s: &str) -> VerifyOutcome {
match s.to_uppercase().as_str() {
"PROVED" => VerifyOutcome::Proved,
"NO_PROOF_FOUND" => VerifyOutcome::NoProofFound,
"INVALID_INPUT" => VerifyOutcome::InvalidInput,
"UNSUPPORTED_FEATURE" => VerifyOutcome::UnsupportedFeature,
"TIMEOUT" => VerifyOutcome::Timeout,
"INCONSISTENT_PREMISES" => VerifyOutcome::InconsistentPremises,
"PROVER_ERROR" => VerifyOutcome::ProverError,
_ => VerifyOutcome::SystemError,
}
}
/// Loose status string for echidnabot's existing GraphQL deserializer,
/// which calls `parse_proof_status` and maps `"VERIFIED" | "PASS" |
/// "SUCCESS"` → `Verified`, `"FAILED" | "FAIL"` → `Failed`, etc.
pub fn loose_status(self) -> &'static str {
match self {
VerifyOutcome::Proved => "VERIFIED",
VerifyOutcome::NoProofFound => "FAILED",
VerifyOutcome::InvalidInput => "FAILED",
VerifyOutcome::UnsupportedFeature => "ERROR",
VerifyOutcome::Timeout => "TIMEOUT",
VerifyOutcome::InconsistentPremises => "ERROR",
VerifyOutcome::ProverError => "ERROR",
VerifyOutcome::SystemError => "ERROR",
}
}
}
/// Result of the `verifyProof` mutation.
///
/// The `status`, `message`, `proverOutput`, `durationMs`, and `artifacts`
/// fields match echidnabot's existing client-side `VerifyProofData`. The
/// `outcome`, `mode`, and `smtStatus` fields surface the typed REST
/// taxonomy so future clients no longer need to round-trip via `/api/verify`
/// to disambiguate Timeout vs NoProofFound.
#[derive(Debug, Clone, SimpleObject)]
pub struct VerifyProofResult {
/// Loose status string for backward compatibility with echidnabot's
/// existing client (`"VERIFIED" | "FAILED" | "TIMEOUT" | "ERROR"`).
pub status: String,
/// Human-readable message.
pub message: String,
/// Captured stdout/stderr from the prover backend.
pub prover_output: String,
/// Wall-clock duration in milliseconds.
pub duration_ms: u64,
/// Output artifacts (proof certificates, intermediate files).
pub artifacts: Vec<String>,
/// Typed outcome — see `VerifyOutcome`.
pub outcome: VerifyOutcome,
/// Optional dispatch mode (e.g. `"smt-query"` for raw SMT-LIB).
pub mode: Option<String>,
/// Optional SMT solver status (`"sat" | "unsat" | "unknown"`).
pub smt_status: Option<String>,
}
/// A single suggested tactic from the Julia ML coprocessor (or fallback).
///
/// Distinct from the existing `Tactic` SimpleObject (which is returned by
/// `suggestTacticsByProofId`) — that one carries `name`/`args`/`description`,
/// this one carries the rank-aware `tactic`/`confidence`/`explanation` shape
/// the echidnabot client expects.
#[derive(Debug, Clone, SimpleObject)]
pub struct SuggestedTactic {
/// The tactic name (e.g. `"intro"`, `"apply foo"`).
pub tactic: String,
/// Confidence score from the ML coprocessor in `[0.0, 1.0]`.
pub confidence: f64,
/// Optional natural-language explanation for the suggestion.
pub explanation: Option<String>,
}
/// Per-prover status, as returned by the `proverStatus` query.
///
/// Complements the existing `provers` list-query, which returns availability
/// for every prover. Use `proverStatus` when you only care about a single
/// prover and want to avoid the full list cost.
#[derive(Debug, Clone, SimpleObject)]
pub struct ProverStatusInfo {
/// True when the prover backend is constructable and its executable
/// is reachable.
pub available: bool,
/// Diagnostic message — version string when available, error text
/// when not.
pub message: Option<String>,
}
pub struct QueryRoot;
#[Object]
impl QueryRoot {
/// Get all available provers (all 30)
async fn provers(&self, _ctx: &Context<'_>) -> Result<Vec<ProverInfo>> {
let provers: Vec<ProverInfo> = CoreProverKind::all()
.into_iter()
.map(|kind| ProverInfo {
kind: core_to_gql(&kind),
version: format!("{:?} (ECHIDNA v0.1.0)", kind),
tier: kind.tier() as i32,
complexity: kind.complexity() as i32,
available: true,
})
.collect();
Ok(provers)
}
/// Get proof state by ID
async fn proof_state(&self, ctx: &Context<'_>, id: String) -> Result<Option<ProofState>> {
let echidna_ctx = ctx.data::<EchidnaContext>()?;
let sessions = echidna_ctx.sessions.read().await;
let session_arc = match sessions.get(&id) {
Some(s) => s.clone(),
None => return Ok(None),
};
drop(sessions);
let session = session_arc.lock().await;
let elapsed = session.start_time.elapsed().as_secs_f64();
let script: Vec<String> = session
.state
.as_ref()
.map(|s| s.proof_script.iter().map(|t| format!("{:?}", t)).collect())
.unwrap_or_default();
let goals_remaining = session
.state
.as_ref()
.map(|s| s.goals.len() as i32)
.unwrap_or_else(|| 0);
let status = match session.status {
crate::resolvers::SessionStatus::Pending => ProofStatus::Pending,
crate::resolvers::SessionStatus::InProgress => ProofStatus::InProgress,
crate::resolvers::SessionStatus::Success => ProofStatus::Success,
crate::resolvers::SessionStatus::Failed => ProofStatus::Failed,
};
Ok(Some(ProofState {
id: session.id.clone(),
prover: core_to_gql(&session.prover_kind),
goal: session.goal.clone(),
status,
proof_script: script,
goals_remaining,
time_elapsed: Some(elapsed),
error_message: None,
}))
}
/// List all proof attempts
async fn list_proofs(
&self,
ctx: &Context<'_>,
limit: Option<i32>,
_status: Option<ProofStatus>,
) -> Result<Vec<ProofState>> {
let echidna_ctx = ctx.data::<EchidnaContext>()?;
let sessions = echidna_ctx.sessions.read().await;
let max = limit.unwrap_or(100) as usize;
let mut proofs = Vec::new();
for (_, session_arc) in sessions.iter().take(max) {
let session = session_arc.lock().await;
let elapsed = session.start_time.elapsed().as_secs_f64();
let script: Vec<String> = session
.state
.as_ref()
.map(|s| s.proof_script.iter().map(|t| format!("{:?}", t)).collect())
.unwrap_or_default();
let goals_remaining = session
.state
.as_ref()
.map(|s| s.goals.len() as i32)
.unwrap_or_else(|| 0);
let status = match session.status {
crate::resolvers::SessionStatus::Pending => ProofStatus::Pending,
crate::resolvers::SessionStatus::InProgress => ProofStatus::InProgress,
crate::resolvers::SessionStatus::Success => ProofStatus::Success,
crate::resolvers::SessionStatus::Failed => ProofStatus::Failed,
};
proofs.push(ProofState {
id: session.id.clone(),
prover: core_to_gql(&session.prover_kind),
goal: session.goal.clone(),
status,
proof_script: script,
goals_remaining,
time_elapsed: Some(elapsed),
error_message: None,
});
}
Ok(proofs)
}
/// Get suggested tactics for an existing proof session by ID.
///
/// **Renamed 2026-06-01 (issue #180)**: this operation used to be
/// exposed as `suggestTactics`. It was renamed to
/// `suggestTacticsByProofId` to free the `suggestTactics` name for the
/// new mutation that the echidnabot client expects (which takes
/// `prover`/`context`/`goalState` and returns
/// `[SuggestedTactic]`). Callers that were using the old
/// `query { suggestTactics(proofId, limit) }` shape must update to
/// `query { suggestTacticsByProofId(proofId, limit) }`.
async fn suggest_tactics_by_proof_id(
&self,
ctx: &Context<'_>,
proof_id: String,
limit: Option<i32>,
) -> Result<Vec<Tactic>> {
let echidna_ctx = ctx.data::<EchidnaContext>()?;
let max = limit.unwrap_or(5) as usize;
let core_tactics = echidna_ctx
.suggest_tactics(&proof_id, max)
.await
.map_err(|e| async_graphql::Error::new(e.to_string()))?;
Ok(core_tactics
.iter()
.map(|t| Tactic {
name: format!("{:?}", t),
args: vec![],
description: Some("Suggested tactic".to_string()),
confidence: None,
})
.collect())
}
/// Per-prover availability/health.
///
/// Added 2026-06-01 for issue #180. Complements the `provers`
/// list-query for the common single-prover case. Backend construction
/// + a `version()` probe is the strongest "available right now"
/// signal we can give without actually dispatching a proof.
async fn prover_status(&self, _ctx: &Context<'_>, prover: String) -> Result<ProverStatusInfo> {
let core_kind = match CoreProverKind::from_str(&prover) {
Ok(k) => k,
Err(e) => {
return Ok(ProverStatusInfo {
available: false,
message: Some(format!("Unknown prover '{}': {}", prover, e)),
});
},
};
let config = ProverConfig::default();
let backend = match ProverFactory::create(core_kind, config) {
Ok(b) => b,
Err(e) => {
return Ok(ProverStatusInfo {
available: false,
message: Some(format!("Failed to construct backend: {}", e)),
});
},
};
match backend.version().await {
Ok(v) => Ok(ProverStatusInfo {
available: true,
message: Some(v),
}),
Err(e) => Ok(ProverStatusInfo {
available: false,
message: Some(format!("Version probe failed: {}", e)),
}),
}
}
/// Health check
async fn health(&self) -> String {
"OK".to_string()
}
}
pub struct MutationRoot;
#[Object]
impl MutationRoot {
/// Submit a new proof goal
async fn submit_proof(
&self,
ctx: &Context<'_>,
goal: String,
prover: ProverKind,
) -> Result<ProofState> {
let echidna_ctx = ctx.data::<EchidnaContext>()?;
let core_kind = gql_to_core(&prover);
let proof_id = echidna_ctx
.create_session(&goal, core_kind)
.await
.map_err(|e| async_graphql::Error::new(e.to_string()))?;
// Fetch back the created session state
let sessions = echidna_ctx.sessions.read().await;
let session_arc = sessions.get(&proof_id).unwrap().clone();
drop(sessions);
let session = session_arc.lock().await;
let script: Vec<String> = session
.state
.as_ref()
.map(|s| s.proof_script.iter().map(|t| format!("{:?}", t)).collect())
.unwrap_or_default();
let goals_remaining = session
.state
.as_ref()
.map(|s| s.goals.len() as i32)
.unwrap_or_else(|| 0);
Ok(ProofState {
id: proof_id,
prover,
goal,
status: ProofStatus::InProgress,
proof_script: script,
goals_remaining,
time_elapsed: Some(0.0),
error_message: None,
})
}
/// Apply a tactic to a proof state
async fn apply_tactic(
&self,
ctx: &Context<'_>,
proof_id: String,
tactic: String,
args: Vec<String>,
) -> Result<ProofState> {
let echidna_ctx = ctx.data::<EchidnaContext>()?;
let core_tactic = parse_tactic(&tactic, &args);
let result = echidna_ctx
.apply_tactic(&proof_id, core_tactic)
.await
.map_err(|e| async_graphql::Error::new(e.to_string()))?;
// Fetch updated state
let sessions = echidna_ctx.sessions.read().await;
let session_arc = sessions
.get(&proof_id)
.ok_or_else(|| async_graphql::Error::new("Session not found"))?
.clone();
drop(sessions);
let session = session_arc.lock().await;
let elapsed = session.start_time.elapsed().as_secs_f64();
let script: Vec<String> = session
.state
.as_ref()
.map(|s| s.proof_script.iter().map(|t| format!("{:?}", t)).collect())
.unwrap_or_default();
let goals_remaining = session
.state
.as_ref()
.map(|s| s.goals.len() as i32)
.unwrap_or_else(|| 0);
let status = match session.status {
crate::resolvers::SessionStatus::Pending => ProofStatus::Pending,
crate::resolvers::SessionStatus::InProgress => ProofStatus::InProgress,
crate::resolvers::SessionStatus::Success => ProofStatus::Success,
crate::resolvers::SessionStatus::Failed => ProofStatus::Failed,
};
Ok(ProofState {
id: session.id.clone(),
prover: core_to_gql(&session.prover_kind),
goal: session.goal.clone(),
status,
proof_script: script,
goals_remaining,
time_elapsed: Some(elapsed),
error_message: match &result {
CoreTacticResult::Error(msg) => Some(msg.clone()),
_ => None,
},
})
}
/// Cancel a proof attempt
async fn cancel_proof(&self, ctx: &Context<'_>, proof_id: String) -> Result<bool> {
let echidna_ctx = ctx.data::<EchidnaContext>()?;
let mut sessions = echidna_ctx.sessions.write().await;
Ok(sessions.remove(&proof_id).is_some())
}
/// Synchronous one-shot proof verification.
///
/// Added 2026-06-01 (issue #180). Matches the echidnabot client's
/// `verifyProof(prover, content)` signature and returns the same
/// fields the client already deserializes (`status`, `message`,
/// `proverOutput`, `durationMs`, `artifacts`), plus the typed
/// `outcome` / `mode` / `smtStatus` fields that surface the REST
/// `/api/verify` taxonomy through GraphQL.
///
/// `prover` is a free-form string parsed via `CoreProverKind::from_str`
/// (same set of aliases as the REST handler). Unknown prover names
/// produce a `SystemError` outcome rather than a GraphQL error so the
/// client gets a structured response in every case.
async fn verify_proof(
&self,
_ctx: &Context<'_>,
prover: String,
content: String,
) -> Result<VerifyProofResult> {
let started = Instant::now();
let core_kind = match CoreProverKind::from_str(&prover) {
Ok(k) => k,
Err(e) => {
let duration_ms = started.elapsed().as_millis() as u64;
return Ok(VerifyProofResult {
status: VerifyOutcome::SystemError.loose_status().to_string(),
message: format!("Unknown prover '{}': {}", prover, e),
prover_output: String::new(),
duration_ms,
artifacts: Vec::new(),
outcome: VerifyOutcome::SystemError,
mode: None,
smt_status: None,
});
},
};
let config = ProverConfig::default();
let backend = match ProverFactory::create(core_kind, config) {
Ok(b) => b,
Err(e) => {
let duration_ms = started.elapsed().as_millis() as u64;
return Ok(VerifyProofResult {
status: VerifyOutcome::SystemError.loose_status().to_string(),
message: format!("Failed to construct backend: {}", e),
prover_output: String::new(),
duration_ms,
artifacts: Vec::new(),
outcome: VerifyOutcome::SystemError,
mode: None,
smt_status: None,
});
},
};
// Parse — failures map onto INVALID_INPUT, matching REST semantics.
let state = match backend.parse_string(&content).await {
Ok(s) => s,
Err(_) => {
let duration_ms = started.elapsed().as_millis() as u64;
return Ok(VerifyProofResult {
status: VerifyOutcome::InvalidInput.loose_status().to_string(),
message: "Parse failed".to_string(),
prover_output: String::new(),
duration_ms,
artifacts: Vec::new(),
outcome: VerifyOutcome::InvalidInput,
mode: None,
smt_status: None,
});
},
};
match backend.verify_proof(&state).await {
Ok(valid) => {
let duration_ms = started.elapsed().as_millis() as u64;
let outcome = if valid {
VerifyOutcome::Proved
} else {
VerifyOutcome::NoProofFound
};
Ok(VerifyProofResult {
status: outcome.loose_status().to_string(),
message: if valid {
"Proof verified successfully".to_string()
} else {
"Proof verification failed".to_string()
},
prover_output: String::new(),
duration_ms,
artifacts: Vec::new(),
outcome,
mode: None,
smt_status: None,
})
},
Err(e) => {
let duration_ms = started.elapsed().as_millis() as u64;
Ok(VerifyProofResult {
status: VerifyOutcome::ProverError.loose_status().to_string(),
message: format!("Verification error: {}", e),
prover_output: String::new(),
duration_ms,
artifacts: Vec::new(),
outcome: VerifyOutcome::ProverError,
mode: None,
smt_status: None,
})
},
}
}
/// Request tactic suggestions for an ad-hoc goal, without a proof
/// session.
///
/// **Added 2026-06-01 (issue #180)**. Matches the echidnabot client's
/// `suggestTactics(prover, context, goalState)` signature. The
/// previous query named `suggestTactics(proofId, limit)` has been
/// renamed to `suggestTacticsByProofId` (see that resolver's docstring).
///
/// This is a mutation rather than a query because it can trigger
/// expensive ML-coprocessor work, mirroring the client's contract.
async fn suggest_tactics(
&self,
ctx: &Context<'_>,
prover: String,
context: String,
goal_state: String,
) -> Result<Vec<SuggestedTactic>> {
let echidna_ctx = ctx.data::<EchidnaContext>()?;
let suggestions = echidna_ctx
.suggest_tactics_for_goal(&prover, &context, &goal_state, 5)
.await
.map_err(|e| async_graphql::Error::new(e.to_string()))?;
Ok(suggestions)
}
}
// ========== Helpers ==========
fn parse_tactic(name: &str, args: &[String]) -> CoreTactic {
match name.to_lowercase().as_str() {
"apply" => CoreTactic::Apply(args.first().cloned().unwrap_or_default()),
"intro" => CoreTactic::Intro(args.first().cloned()),
"rewrite" => CoreTactic::Rewrite(args.first().cloned().unwrap_or_default()),
"simplify" | "simp" => CoreTactic::Simplify,
"reflexivity" | "refl" => CoreTactic::Reflexivity,
"assumption" => CoreTactic::Assumption,
"cases" => CoreTactic::Cases(Term::Var(args.first().cloned().unwrap_or_default())),
"induction" => CoreTactic::Induction(Term::Var(args.first().cloned().unwrap_or_default())),
"exact" => CoreTactic::Exact(Term::Var(args.first().cloned().unwrap_or_default())),
_ => CoreTactic::Custom {
prover: "graphql".to_string(),
command: name.to_string(),
args: args.to_vec(),
},
}
}
fn core_to_gql(kind: &CoreProverKind) -> ProverKind {
match kind {
CoreProverKind::Agda => ProverKind::Agda,
CoreProverKind::Coq => ProverKind::Coq,
CoreProverKind::Lean => ProverKind::Lean,
CoreProverKind::Isabelle => ProverKind::Isabelle,
CoreProverKind::Z3 => ProverKind::Z3,
CoreProverKind::CVC5 => ProverKind::CVC5,
CoreProverKind::Metamath => ProverKind::Metamath,
CoreProverKind::HOLLight => ProverKind::HOLLight,
CoreProverKind::Mizar => ProverKind::Mizar,
CoreProverKind::PVS => ProverKind::PVS,
CoreProverKind::ACL2 => ProverKind::ACL2,
CoreProverKind::HOL4 => ProverKind::HOL4,
CoreProverKind::Idris2 => ProverKind::Idris2,
CoreProverKind::Vampire => ProverKind::Vampire,
CoreProverKind::EProver => ProverKind::EProver,
CoreProverKind::SPASS => ProverKind::SPASS,
CoreProverKind::AltErgo => ProverKind::AltErgo,
CoreProverKind::FStar => ProverKind::FStar,
CoreProverKind::Dafny => ProverKind::Dafny,
CoreProverKind::Why3 => ProverKind::Why3,
CoreProverKind::TLAPS => ProverKind::TLAPS,
CoreProverKind::Twelf => ProverKind::Twelf,
CoreProverKind::Nuprl => ProverKind::Nuprl,
CoreProverKind::Minlog => ProverKind::Minlog,
CoreProverKind::Imandra => ProverKind::Imandra,
CoreProverKind::GLPK => ProverKind::GLPK,
CoreProverKind::SCIP => ProverKind::SCIP,
CoreProverKind::MiniZinc => ProverKind::MiniZinc,
CoreProverKind::Chuffed => ProverKind::Chuffed,
CoreProverKind::ORTools => ProverKind::ORTools,
CoreProverKind::Lean3 => ProverKind::Lean3,
CoreProverKind::TypedWasm => ProverKind::TypedWasm,
CoreProverKind::SPIN => ProverKind::SPIN,
CoreProverKind::CBMC => ProverKind::CBMC,
CoreProverKind::SeaHorn => ProverKind::SeaHorn,
CoreProverKind::CaDiCaL => ProverKind::CaDiCaL,
CoreProverKind::Kissat => ProverKind::Kissat,
CoreProverKind::MiniSat => ProverKind::MiniSat,
CoreProverKind::NuSMV => ProverKind::NuSMV,
CoreProverKind::TLC => ProverKind::TLC,
CoreProverKind::Alloy => ProverKind::Alloy,
CoreProverKind::Prism => ProverKind::Prism,
CoreProverKind::UPPAAL => ProverKind::UPPAAL,
CoreProverKind::FramaC => ProverKind::FramaC,
CoreProverKind::Viper => ProverKind::Viper,
CoreProverKind::Tamarin => ProverKind::Tamarin,
CoreProverKind::ProVerif => ProverKind::ProVerif,
CoreProverKind::KeY => ProverKind::KeY,
CoreProverKind::DReal => ProverKind::DReal,
CoreProverKind::ABC => ProverKind::ABC,
CoreProverKind::TypeLL => ProverKind::TypeLL,
CoreProverKind::KatagoriaVerifier => ProverKind::KatagoriaVerifier,
CoreProverKind::TropicalTypeChecker => ProverKind::TropicalTypeChecker,
CoreProverKind::ChoreographicTypeChecker => ProverKind::ChoreographicTypeChecker,
CoreProverKind::EpistemicTypeChecker => ProverKind::EpistemicTypeChecker,
CoreProverKind::EchoTypeChecker => ProverKind::EchoTypeChecker,
CoreProverKind::SessionTypeChecker => ProverKind::SessionTypeChecker,
CoreProverKind::ModalTypeChecker => ProverKind::ModalTypeChecker,
CoreProverKind::QTTTypeChecker => ProverKind::QTTTypeChecker,
CoreProverKind::EffectRowTypeChecker => ProverKind::EffectRowTypeChecker,
CoreProverKind::DependentTypeChecker => ProverKind::DependentTypeChecker,
CoreProverKind::RefinementTypeChecker => ProverKind::RefinementTypeChecker,
CoreProverKind::OrdinaryTypeChecker => ProverKind::OrdinaryTypeChecker,
CoreProverKind::PhantomTypeChecker => ProverKind::PhantomTypeChecker,
CoreProverKind::PolymorphicTypeChecker => ProverKind::PolymorphicTypeChecker,
CoreProverKind::ExistentialTypeChecker => ProverKind::ExistentialTypeChecker,
CoreProverKind::HigherKindedTypeChecker => ProverKind::HigherKindedTypeChecker,
CoreProverKind::RowTypeChecker => ProverKind::RowTypeChecker,
CoreProverKind::SubtypingTypeChecker => ProverKind::SubtypingTypeChecker,
CoreProverKind::IntersectionTypeChecker => ProverKind::IntersectionTypeChecker,
CoreProverKind::UnionTypeChecker => ProverKind::UnionTypeChecker,
CoreProverKind::GradualTypeChecker => ProverKind::GradualTypeChecker,
CoreProverKind::HoareTypeChecker => ProverKind::HoareTypeChecker,
CoreProverKind::IndexedTypeChecker => ProverKind::IndexedTypeChecker,
CoreProverKind::LinearTypeChecker => ProverKind::LinearTypeChecker,
CoreProverKind::AffineTypeChecker => ProverKind::AffineTypeChecker,
CoreProverKind::RelevantTypeChecker => ProverKind::RelevantTypeChecker,
CoreProverKind::OrderedTypeChecker => ProverKind::OrderedTypeChecker,
CoreProverKind::UniquenessTypeChecker => ProverKind::UniquenessTypeChecker,
CoreProverKind::ImmutableTypeChecker => ProverKind::ImmutableTypeChecker,
CoreProverKind::CapabilityTypeChecker => ProverKind::CapabilityTypeChecker,
CoreProverKind::BunchedTypeChecker => ProverKind::BunchedTypeChecker,
CoreProverKind::TemporalTypeChecker => ProverKind::TemporalTypeChecker,
CoreProverKind::ProvabilityTypeChecker => ProverKind::ProvabilityTypeChecker,
CoreProverKind::ImpureTypeChecker => ProverKind::ImpureTypeChecker,
CoreProverKind::CoeffectTypeChecker => ProverKind::CoeffectTypeChecker,
CoreProverKind::ProbabilisticTypeChecker => ProverKind::ProbabilisticTypeChecker,
CoreProverKind::DyadicTypeChecker => ProverKind::DyadicTypeChecker,
CoreProverKind::HomotopyTypeChecker => ProverKind::HomotopyTypeChecker,
CoreProverKind::CubicalTypeChecker => ProverKind::CubicalTypeChecker,
CoreProverKind::NominalTypeChecker => ProverKind::NominalTypeChecker,
CoreProverKind::Abella => ProverKind::Abella,
CoreProverKind::Dedukti => ProverKind::Dedukti,
CoreProverKind::Cameleer => ProverKind::Cameleer,
CoreProverKind::ACL2s => ProverKind::ACL2s,
CoreProverKind::IsabelleZF => ProverKind::IsabelleZF,
CoreProverKind::Boogie => ProverKind::Boogie,
CoreProverKind::Naproche => ProverKind::Naproche,
CoreProverKind::Matita => ProverKind::Matita,
CoreProverKind::Arend => ProverKind::Arend,
CoreProverKind::Athena => ProverKind::Athena,
CoreProverKind::LambdaProlog => ProverKind::LambdaProlog,
CoreProverKind::Mercury => ProverKind::Mercury,
CoreProverKind::Nitpick => ProverKind::Nitpick,
CoreProverKind::Nunchaku => ProverKind::Nunchaku,
CoreProverKind::CubicalAgda => ProverKind::CubicalAgda,
CoreProverKind::Zipperposition => ProverKind::Zipperposition,
CoreProverKind::Prover9 => ProverKind::Prover9,
CoreProverKind::OpenSmt => ProverKind::OpenSmt,
CoreProverKind::SmtRat => ProverKind::SmtRat,
CoreProverKind::Rocq => ProverKind::Rocq,
CoreProverKind::UppaalStratego => ProverKind::UppaalStratego,
CoreProverKind::MizAR => ProverKind::MizAR,
CoreProverKind::GPUVerify => ProverKind::GPUVerify,
CoreProverKind::Faial => ProverKind::Faial,
CoreProverKind::Leo3 => ProverKind::Leo3,
CoreProverKind::Satallax => ProverKind::Satallax,
CoreProverKind::Lash => ProverKind::Lash,
CoreProverKind::AgsyHOL => ProverKind::AgsyHOL,
CoreProverKind::IProver => ProverKind::IProver,
CoreProverKind::Princess => ProverKind::Princess,
CoreProverKind::Twee => ProverKind::Twee,
CoreProverKind::MetiTarski => ProverKind::MetiTarski,
CoreProverKind::CSI => ProverKind::CSI,
CoreProverKind::AProVE => ProverKind::AProVE,
CoreProverKind::GNATprove => ProverKind::GNATprove,
CoreProverKind::Stainless => ProverKind::Stainless,
CoreProverKind::LiquidHaskell => ProverKind::LiquidHaskell,
CoreProverKind::KeYmaeraX => ProverKind::KeYmaeraX,
CoreProverKind::Qepcad => ProverKind::Qepcad,
CoreProverKind::Redlog => ProverKind::Redlog,
CoreProverKind::MleanCoP => ProverKind::MleanCoP,
CoreProverKind::IleanCoP => ProverKind::IleanCoP,
CoreProverKind::NanoCoP => ProverKind::NanoCoP,
CoreProverKind::MetTeL2 => ProverKind::MetTeL2,
CoreProverKind::ELK => ProverKind::ELK,
CoreProverKind::Konclude => ProverKind::Konclude,
CoreProverKind::Storm => ProverKind::Storm,
CoreProverKind::ProB => ProverKind::ProB,
CoreProverKind::EasyCrypt => ProverKind::EasyCrypt,
CoreProverKind::CryptoVerif => ProverKind::CryptoVerif,
}
}
fn gql_to_core(kind: &ProverKind) -> CoreProverKind {
match kind {
ProverKind::Agda => CoreProverKind::Agda,
ProverKind::Coq => CoreProverKind::Coq,
ProverKind::Lean => CoreProverKind::Lean,
ProverKind::Isabelle => CoreProverKind::Isabelle,
ProverKind::Z3 => CoreProverKind::Z3,
ProverKind::CVC5 => CoreProverKind::CVC5,
ProverKind::Metamath => CoreProverKind::Metamath,
ProverKind::HOLLight => CoreProverKind::HOLLight,
ProverKind::Mizar => CoreProverKind::Mizar,
ProverKind::PVS => CoreProverKind::PVS,
ProverKind::ACL2 => CoreProverKind::ACL2,
ProverKind::HOL4 => CoreProverKind::HOL4,
ProverKind::Idris2 => CoreProverKind::Idris2,
ProverKind::Vampire => CoreProverKind::Vampire,
ProverKind::EProver => CoreProverKind::EProver,
ProverKind::SPASS => CoreProverKind::SPASS,
ProverKind::AltErgo => CoreProverKind::AltErgo,
ProverKind::FStar => CoreProverKind::FStar,
ProverKind::Dafny => CoreProverKind::Dafny,
ProverKind::Why3 => CoreProverKind::Why3,
ProverKind::TLAPS => CoreProverKind::TLAPS,
ProverKind::Twelf => CoreProverKind::Twelf,
ProverKind::Nuprl => CoreProverKind::Nuprl,
ProverKind::Minlog => CoreProverKind::Minlog,
ProverKind::Imandra => CoreProverKind::Imandra,
ProverKind::GLPK => CoreProverKind::GLPK,
ProverKind::SCIP => CoreProverKind::SCIP,
ProverKind::MiniZinc => CoreProverKind::MiniZinc,
ProverKind::Chuffed => CoreProverKind::Chuffed,
ProverKind::ORTools => CoreProverKind::ORTools,
ProverKind::Lean3 => CoreProverKind::Lean3,
ProverKind::TypedWasm => CoreProverKind::TypedWasm,
ProverKind::SPIN => CoreProverKind::SPIN,
ProverKind::CBMC => CoreProverKind::CBMC,
ProverKind::SeaHorn => CoreProverKind::SeaHorn,
ProverKind::CaDiCaL => CoreProverKind::CaDiCaL,
ProverKind::Kissat => CoreProverKind::Kissat,
ProverKind::MiniSat => CoreProverKind::MiniSat,
ProverKind::NuSMV => CoreProverKind::NuSMV,
ProverKind::TLC => CoreProverKind::TLC,
ProverKind::Alloy => CoreProverKind::Alloy,
ProverKind::Prism => CoreProverKind::Prism,
ProverKind::UPPAAL => CoreProverKind::UPPAAL,
ProverKind::FramaC => CoreProverKind::FramaC,
ProverKind::Viper => CoreProverKind::Viper,
ProverKind::Tamarin => CoreProverKind::Tamarin,
ProverKind::ProVerif => CoreProverKind::ProVerif,
ProverKind::KeY => CoreProverKind::KeY,
ProverKind::DReal => CoreProverKind::DReal,
ProverKind::ABC => CoreProverKind::ABC,
ProverKind::TypeLL => CoreProverKind::TypeLL,