Skip to main content

Overview

Policies are the core decision-making engine of the ZKScore Trust Layer. They define flexible rules that evaluate user attestations to make access control, risk assessment, and other trust-based decisions in your applications.
Think of policies as smart contracts for trust decisions. They take user attestations as input and produce structured decisions as output, enabling your application to make automated trust-based choices.

What are Policies?

A policy is a structured set of conditions that can be evaluated against a user’s attestations to make decisions. Policies are:
  • Composable - Can be combined and nested
  • Versioned - Support evolution and updates
  • Flexible - Handle complex decision logic
  • Testable - Can be validated before deployment
  • Transparent - Decision logic is auditable

Policy Structure

Every policy follows a standardized JSON structure:

Policy Components

1. Policy Metadata

2. Conditions

Conditions define the requirements that must be met for a policy to pass.

Basic Condition Types

Attestation Existence
Check if a user has specific attestations:
Data Conditions
Evaluate specific fields in attestation data:
Supported Operators:
  • eq - Equal to
  • ne - Not equal to
  • gt - Greater than
  • gte - Greater than or equal to
  • lt - Less than
  • lte - Less than or equal to
  • in - In array
  • nin - Not in array
  • contains - Array contains value
  • regex - Regular expression match
Composite Conditions
Combine multiple conditions with logical operators:
Supported Logic Operators:
  • AND - All conditions must be true
  • OR - At least one condition must be true
  • NOT - Condition must be false
Time-based Conditions
Evaluate time-based requirements:
Score Conditions
Evaluate trust scores:

3. Decision Structure

The decision defines what happens when a policy passes or fails.

Allow Decision

Deny Decision

Conditional Decision

Creating Policies

2. Via Smart Contract

3. Policy Templates

ZKScore provides pre-built policy templates for common use cases:

Policy Evaluation

1. Basic Evaluation

2. Batch Evaluation

3. Advanced Evaluation with Custom Context

Policy Types and Use Cases

1. Access Control Policies

Control who can access features or resources:

2. Risk Assessment Policies

Evaluate risk levels for financial decisions:

3. Compliance Policies

Ensure regulatory and legal compliance:

4. Reputation Policies

Calculate and evaluate reputation scores:

Policy Testing and Validation

1. Test Policy with Sample Data

2. Policy Validation

3. Policy Simulation

Policy Management

1. Update Existing Policies

2. Policy Versioning

3. Policy Deprecation

Integration Examples

1. Express.js Middleware

2. React Hook for Policy Evaluation

3. Smart Contract Integration

Best Practices

1. Policy Design

  • Keep it simple: Start with basic conditions and add complexity gradually
  • Clear error messages: Provide helpful feedback when policies fail
  • Version control: Use semantic versioning for policy updates
  • Documentation: Document policy logic and use cases
  • Testing: Test policies with various scenarios before deployment

2. Performance

  • Efficient conditions: Order conditions by selectivity (most selective first)
  • Caching: Cache policy evaluation results when appropriate
  • Batch evaluation: Use batch evaluation for multiple policies
  • Indexing: Ensure attestation data is properly indexed

3. Security

  • Input validation: Validate all policy inputs and context data
  • Access control: Restrict policy creation and modification to authorized users
  • Audit trails: Log all policy evaluations and decisions
  • Regular review: Periodically review and update policies

4. User Experience

  • Clear requirements: Make policy requirements transparent to users
  • Helpful feedback: Provide actionable suggestions when policies fail
  • Progressive disclosure: Gradually introduce users to policy requirements
  • Alternative paths: Provide alternative ways to meet policy requirements

Common Patterns

1. Tiered Access Control

2. Time-based Requirements

3. Composite Risk Assessment