├── Zen-Icon.png
├── .stylecop
├── AnalysisDictionary.xml
├── stylecop.json
└── StyleCop.props
├── ZenLib
├── DataTypes
│ ├── Unit.cs
│ └── UInt.cs
├── Solver
│ ├── SolverDebugInfo.cs
│ ├── SolverType.cs
│ └── SolverConfig.cs
├── Configuration
│ ├── ZenObjectAttribute.cs
│ ├── ZenGenerationConfiguration.cs
│ ├── ZenSizeAttribute.cs
│ └── ZenSettings.cs
├── ModelChecking
│ ├── Backend
│ │ ├── ModelCheckerContext.cs
│ │ ├── SymbolicEvaluationEnvironment.cs
│ │ ├── IModelChecker.cs
│ │ ├── ZenSolution.cs
│ │ └── ModelCheckerFactory.cs
│ ├── InterleavingAnalysis
│ │ ├── InterleavingResult.cs
│ │ ├── InterleavingClass.cs
│ │ └── InterleavingSet.cs
│ ├── Transformer
│ │ ├── StateSetMetadata.cs
│ │ └── StateSetTransformerManager.cs
│ └── Representation
│ │ ├── SymbolicValue.cs
│ │ ├── SymbolicReal.cs
│ │ ├── SymbolicSeq.cs
│ │ ├── SymbolicString.cs
│ │ ├── SymbolicMap.cs
│ │ ├── SymbolicInteger.cs
│ │ ├── SymbolicBitvec.cs
│ │ ├── SymbolicChar.cs
│ │ ├── SymbolicBool.cs
│ │ ├── SymbolicFSeq.cs
│ │ ├── SymbolicConstMap.cs
│ │ ├── ISymbolicValueVisitor.cs
│ │ └── SymbolicObject.cs
├── Common
│ ├── ZenTimeoutException.cs
│ ├── ZenException.cs
│ ├── ZenUnreachableException.cs
│ ├── LazyString.cs
│ ├── Contract.cs
│ └── FiniteCache.cs
├── TransitionSystem
│ ├── SearchStats.cs
│ ├── SearchOutcome.cs
│ ├── LTL
│ │ ├── Predicate.cs
│ │ ├── Or.cs
│ │ ├── And.cs
│ │ ├── Eventually.cs
│ │ ├── Always.cs
│ │ ├── Not.cs
│ │ └── LTL.cs
│ └── SearchResult.cs
├── Compilation
│ └── ExpressionConverterEnvironment.cs
├── Interpreter
│ ├── Interpreter.cs
│ └── ExpressionEvaluatorEnvironment.cs
├── Language
│ └── Ast
│ │ ├── ZenEnumerableExtensions.cs
│ │ ├── ZenLambda.cs
│ │ ├── ZenArbitraryExpr.cs
│ │ ├── ZenParameterExpr.cs
│ │ ├── ZenAstCache.cs
│ │ ├── ZenConstantExpr.cs
│ │ ├── ZenSeqUnitExpr.cs
│ │ ├── ZenSeqLengthExpr.cs
│ │ ├── ZenCastExpr.cs
│ │ ├── ZenBitwiseNotExpr.cs
│ │ ├── ZenSeqRegexExpr.cs
│ │ ├── ZenSeqNthExpr.cs
│ │ ├── ZenSeqAtExpr.cs
│ │ └── ZenFSeqAddFrontExpr.cs
├── Regex
│ ├── Ast
│ │ ├── RegexEmptyExpr.cs
│ │ ├── RegexEpsilonExpr.cs
│ │ ├── RegexAnchorExpr.cs
│ │ └── RegexRangeExpr.cs
│ └── Visitor
│ │ └── IRegexExprVisitor.cs
├── Formatting
│ └── ExpressionReuseVisitor.cs
├── ZenLib.csproj
└── SymbolicExecution
│ └── PathConstraint.cs
├── CODE_OF_CONDUCT.md
├── ZenLib.Tests
├── Network
│ ├── Network.cs
│ ├── Device.cs
│ ├── ForwardingTable.cs
│ ├── Interface.cs
│ ├── LocatedPacket.cs
│ ├── Prefix.cs
│ └── Ip.cs
├── CharTests.cs
├── TimeoutTests.cs
├── ParallelismTests.cs
├── AttributeTests.cs
├── ZenLib.Tests.csproj
├── MemoryTests.cs
├── ApiTests.cs
├── FlyweightTests.cs
├── EnumerableExtensionsTests.cs
├── FindAllTests.cs
├── DebuggingTests.cs
├── ReflectionTests.cs
├── NatTests.cs
└── RouteMapTests.cs
├── ZenLib.Generators.Tests
├── ZenLib.Generators.Tests.csproj
└── Program.cs
├── ZenLib.Bench
├── Program.cs
├── ZenLib.Bench.csproj
└── AclBench.cs
├── LICENSE
├── .github
└── workflows
│ └── dotnet.yml
├── ZenLib.Generators
└── ZenLib.Generators.csproj
└── SECURITY.md
/Zen-Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/Zen/HEAD/Zen-Icon.png
--------------------------------------------------------------------------------
/.stylecop/AnalysisDictionary.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | kusto
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.stylecop/stylecop.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
3 | "description": "Configuration file for StyleCop Analyzers",
4 | "settings": {
5 | "documentationRules": {
6 | "companyName": "Microsoft"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ZenLib/DataTypes/Unit.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib
6 | {
7 | ///
8 | /// Absence of a value.
9 | ///
10 | public sealed class Unit
11 | {
12 | ///
13 | /// The unit instance.
14 | ///
15 | public static Unit Instance = new Unit();
16 | }
17 | }
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Microsoft Open Source Code of Conduct
2 |
3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4 |
5 | Resources:
6 |
7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
10 |
--------------------------------------------------------------------------------
/ZenLib/Solver/SolverDebugInfo.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib.Solver
6 | {
7 | using System;
8 |
9 | ///
10 | /// Solver debug information for Zen.
11 | ///
12 | public class SolverDebugInfo
13 | {
14 | ///
15 | /// The solver query that was used for Z3.
16 | ///
17 | public String SolverQuery;
18 | }
19 | }
--------------------------------------------------------------------------------
/ZenLib.Tests/Network/Network.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib.Tests.Network
6 | {
7 | using System.Collections.Generic;
8 | using System.Diagnostics.CodeAnalysis;
9 |
10 | ///
11 | /// Network object as a collection of devices.
12 | ///
13 | [ExcludeFromCodeCoverage]
14 | class Network
15 | {
16 | public Dictionary Devices { get; set; }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/ZenLib/Configuration/ZenObjectAttribute.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib
6 | {
7 | using System;
8 |
9 | ///
10 | /// Attribute annotation for classes and structs to generate zen methods.
11 | ///
12 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
13 | public class ZenObjectAttribute : Attribute
14 | {
15 | }
16 | }
--------------------------------------------------------------------------------
/ZenLib/Solver/SolverType.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib.Solver
6 | {
7 | ///
8 | /// Solver type.
9 | ///
10 | public enum SolverType
11 | {
12 | ///
13 | /// DecisionDiagram backend.
14 | ///
15 | DecisionDiagrams,
16 |
17 | ///
18 | /// Z3 backend.
19 | ///
20 | Z3,
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/ZenLib.Generators.Tests/ZenLib.Generators.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 | latest
7 | AnyCPU;x64
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/ZenLib.Tests/Network/Device.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib.Tests.Network
6 | {
7 | using System.Diagnostics.CodeAnalysis;
8 |
9 | ///
10 | /// A device objet.
11 | ///
12 | [ExcludeFromCodeCoverage]
13 | class Device
14 | {
15 | public string Name { get; set; }
16 |
17 | public ForwardingTable Table { get; set; }
18 |
19 | public Interface[] Interfaces { get; set; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ZenLib/ModelChecking/Backend/ModelCheckerContext.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib.ModelChecking
6 | {
7 | ///
8 | /// The type of model checking to be performed.
9 | ///
10 | public enum ModelCheckerContext
11 | {
12 | ///
13 | /// Simple constraint solving.
14 | ///
15 | Solving,
16 |
17 | ///
18 | /// Constrained optimization.
19 | ///
20 | Optimization,
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/ZenLib/Common/ZenTimeoutException.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib
6 | {
7 | using System;
8 |
9 | ///
10 | /// New exception type for a timeout in a solver for Zen..
11 | ///
12 | public class ZenSolverTimeoutException : Exception
13 | {
14 | ///
15 | /// Creates a new instance of the class.
16 | ///
17 | public ZenSolverTimeoutException() : base()
18 | {
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ZenLib/Configuration/ZenGenerationConfiguration.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib
6 | {
7 | ///
8 | /// A generation configuration.
9 | ///
10 | internal class ZenGenerationConfiguration
11 | {
12 | ///
13 | /// The depth at which to generate objects.
14 | ///
15 | public int Depth { get; set; }
16 |
17 | ///
18 | /// An optional name to use for variables.
19 | ///
20 | public string Name { get; set; }
21 | }
22 | }
--------------------------------------------------------------------------------
/ZenLib/TransitionSystem/SearchStats.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib.TransitionSystem
6 | {
7 | ///
8 | /// The search statistics.
9 | ///
10 | public class SearchStats
11 | {
12 | ///
13 | /// The time taken in milliseconds.
14 | ///
15 | public long Time { get; }
16 |
17 | ///
18 | /// Creates a new instance of the class.
19 | ///
20 | /// The time.
21 | public SearchStats(long time)
22 | {
23 | Time = time;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ZenLib/TransitionSystem/SearchOutcome.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib.TransitionSystem
6 | {
7 | ///
8 | /// The search outcome.
9 | ///
10 | public enum SearchOutcome
11 | {
12 | ///
13 | /// A counter example to the safety check.
14 | ///
15 | CounterExample,
16 |
17 | ///
18 | /// A proof that the system is safe.
19 | ///
20 | SafetyProof,
21 |
22 | ///
23 | /// A timeout for the verifier.
24 | ///
25 | Timeout,
26 |
27 | ///
28 | /// A lack of a counter example.
29 | ///
30 | NoCounterExample,
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/ZenLib/Solver/SolverConfig.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib.Solver
6 | {
7 | using System;
8 |
9 | ///
10 | /// Solver configuration for Zen.
11 | ///
12 | public class SolverConfig
13 | {
14 | ///
15 | /// The solver type to use.
16 | ///
17 | public SolverType SolverType { get; set; } = SolverType.Z3;
18 |
19 | ///
20 | /// The solver timeout to use.
21 | ///
22 | public TimeSpan? SolverTimeout { get; set; } = null;
23 |
24 | ///
25 | /// An optional debugging callback with the .
26 | ///
27 | public Action Debug { get; set; } = null;
28 | }
29 | }
--------------------------------------------------------------------------------
/ZenLib.Bench/Program.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLibBench
6 | {
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Numerics;
10 | using ZenLib;
11 | using ZenLib.Solver;
12 |
13 | ///
14 | /// Run a collection of benchmarks for Zen.
15 | ///
16 | public class Program
17 | {
18 | ///
19 | /// Main entry point.
20 | ///
21 | /// Command line args.
22 | static void Main(string[] args)
23 | {
24 | // ZenBench.BenchmarkSets();
25 | // ZenBench.BenchmarkComparisons();
26 | // ZenBench.BenchmarkTransformers();
27 | // ZenBench.BenchmarkTransformerCache();
28 | // ZenBench.BenchmarkAllocation();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ZenLib/Common/ZenException.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib
6 | {
7 | using System;
8 |
9 | ///
10 | /// New exception type for code known to be unreachable at runtime.
11 | ///
12 | public class ZenException : Exception
13 | {
14 | ///
15 | /// Creates a new instance of the class.
16 | ///
17 | ///
18 | public ZenException(string e) : base(e)
19 | {
20 | }
21 |
22 | ///
23 | /// Creates a new instance of the class.
24 | ///
25 | /// The description.
26 | /// The inner exception.
27 | public ZenException(string s, Exception innerException) : base(s, innerException)
28 | {
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ZenLib/Configuration/ZenSizeAttribute.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib
6 | {
7 | using System;
8 |
9 | ///
10 | /// Attribute annotation for fields that provides sizing information to Zen when
11 | /// generating symbolic values of a given type.
12 | ///
13 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
14 | public class ZenSizeAttribute : Attribute
15 | {
16 | ///
17 | /// Initializes a new instance of the class.
18 | ///
19 | /// The depth for this field.
20 | public ZenSizeAttribute(int depth = -1)
21 | {
22 | Depth = depth;
23 | }
24 |
25 | ///
26 | /// Gets the size depth for the field or property.
27 | ///
28 | public int Depth { get; }
29 | }
30 | }
--------------------------------------------------------------------------------
/ZenLib/Compilation/ExpressionConverterEnvironment.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib.Compilation
6 | {
7 | using System.Collections.Immutable;
8 | using System.Linq.Expressions;
9 |
10 | ///
11 | /// An environment for the interpreter.
12 | ///
13 | internal class ExpressionConverterEnvironment
14 | {
15 | ///
16 | /// Initializes a new instance of the class.
17 | ///
18 | /// The initial argument assignment.
19 | public ExpressionConverterEnvironment(ImmutableDictionary argumentAssignment)
20 | {
21 | this.ArgumentAssignment = argumentAssignment;
22 | }
23 |
24 | ///
25 | /// Gets the argument assignment.
26 | ///
27 | public ImmutableDictionary ArgumentAssignment { get; }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ZenLib/Common/ZenUnreachableException.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib
6 | {
7 | using System;
8 | using System.Diagnostics.CodeAnalysis;
9 |
10 | ///
11 | /// Exception for unreachable code.
12 | ///
13 | [ExcludeFromCodeCoverage]
14 | public class ZenUnreachableException : ZenException
15 | {
16 | ///
17 | /// Creates a new instance of the class.
18 | ///
19 | public ZenUnreachableException() : base("Unexpected unreachable code detected.")
20 | {
21 | }
22 |
23 | ///
24 | /// Creates a new instance of the class.
25 | ///
26 | /// The inner exception.
27 | public ZenUnreachableException(Exception innerException) : base("Unexpected unreachable code detected.", innerException)
28 | {
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ZenLib/Configuration/ZenSettings.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib
6 | {
7 | using System;
8 |
9 | ///
10 | /// Settings for Zen.
11 | ///
12 | public static class ZenSettings
13 | {
14 | ///
15 | /// Use a larger stack to avoid stack overflow errors for
16 | /// large problem instances. Default is false.
17 | ///
18 | public static bool UseLargeStack = false;
19 |
20 | ///
21 | /// Maximum stack size since Zen uses deep recursion.
22 | ///
23 | public static int LargeStackSize = 30_000_000;
24 |
25 | ///
26 | /// Whether or not the preserve the structure of If branches.
27 | ///
28 | public static bool PreserveBranches = false;
29 |
30 | ///
31 | /// Whether we are in a separate thread with a larger stack already.
32 | ///
33 | [ThreadStatic] internal static bool InSeparateThread = false;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/ZenLib.Generators.Tests/Program.cs:
--------------------------------------------------------------------------------
1 | namespace ZenLib.Generators.Tests;
2 |
3 | using ZenLib;
4 |
5 | partial class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | var x = Zen.Symbolic();
10 | x.GetId();
11 | x.GetBar();
12 | x.WithBar(Zen.Symbolic());
13 | x.WithId(Zen.Symbolic());
14 |
15 | var y = Zen.Symbolic>();
16 | y.GetField();
17 | y.WithField(0);
18 |
19 | var z = Zen.Symbolic();
20 | z.GetBlah();
21 | z.WithBlah(0);
22 | }
23 | }
24 |
25 | [ZenObject]
26 | public class Point
27 | {
28 | public int X { get; set; }
29 |
30 | public int Y { get; set; }
31 |
32 | public static Zen Add(Zen p1, Zen p2)
33 | {
34 | return p1.WithX(p1.GetX() + p2.GetX()).WithY(p1.GetY() + p2.GetY());
35 | }
36 | }
37 |
38 | [ZenObject]
39 | public class Foo
40 | {
41 | public Real Id { get; set; }
42 |
43 | public int Bar { get; set; }
44 | }
45 |
46 | [ZenObject]
47 | public class Bar
48 | {
49 | public uint Blah;
50 | }
51 |
52 | [ZenObject]
53 | public struct Fat
54 | {
55 | public T Field { get; set; }
56 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
22 |
--------------------------------------------------------------------------------
/ZenLib/ModelChecking/InterleavingAnalysis/InterleavingResult.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Microsoft. All rights reserved.
3 | //
4 |
5 | namespace ZenLib.ModelChecking
6 | {
7 | using System.Collections.Immutable;
8 |
9 | ///
10 | /// Representation of a an interleaving result.
11 | ///
12 | internal abstract class InterleavingResult
13 | {
14 | ///
15 | /// Gets all the possible variables the result could have.
16 | ///
17 | /// The variables as a set.
18 | public abstract ImmutableHashSet