Skip to content

Latest commit

 

History

History
313 lines (248 loc) · 13.1 KB

File metadata and controls

313 lines (248 loc) · 13.1 KB

Identity-Aware Limits Implementation Summary

Overview

This document summarizes the implementation of identity-aware transaction limits using off-chain signed claims for the Grainlify escrow system.

Feature Description

The identity-aware limits feature enables regulatory compliance and risk management by:

  • Accepting signed identity claims from trusted KYC providers
  • Enforcing different transaction limits based on identity tiers (Unverified, Basic, Verified, Premium)
  • Applying risk-based adjustments to limits based on risk scores (0-100)
  • Verifying claim authenticity using Ed25519 cryptographic signatures
  • Storing only tier and risk score on-chain (no personal information)

Implementation Commits

Commit 1: Identity Module Structure

Hash: 1f3267d

Added core identity types and error codes:

  • IdentityTier enum (Unverified, Basic, Verified, Premium)
  • IdentityClaim struct for signed claims
  • AddressIdentity struct for stored identity data
  • TierLimits and RiskThresholds configuration structures
  • Extended Error enum with identity-related errors
  • Updated DataKey enum with identity storage keys

Commit 2: Claim Serialization and Signature Verification

Hash: 1d0922c

Implemented cryptographic functions:

  • serialize_claim() - Deterministic XDR encoding for signatures
  • verify_claim_signature() - Ed25519 signature verification
  • is_claim_expired() - Expiry timestamp checking
  • validate_claim() - Format and field validation
  • calculate_effective_limit() - Tier and risk-based limit calculation

Commit 3: Admin Functions

Hash: 8925a89

Added administrative functions:

  • set_authorized_issuer() - Manage trusted claim issuers
  • set_tier_limits() - Configure tier-based transaction limits
  • set_risk_thresholds() - Configure risk-based adjustments
  • Initialize default limits and thresholds in init()
  • Emit events for issuer management actions

Commit 4: Claim Submission and Limit Enforcement

Hash: 7093038

Implemented core functionality:

  • submit_identity_claim() - Verify and store identity claims
  • get_address_identity() - Query identity data for addresses
  • get_effective_limit() - Calculate effective transaction limits
  • is_claim_valid() - Check claim validity
  • enforce_transaction_limit() - Internal limit enforcement
  • Integrated limit checks into lock_funds() and release_funds()
  • Emit events for claim submission, rejection, and limit enforcement

Commit 5: Off-Chain Helper (Go)

Hash: deb80f2

Created Go package for off-chain claim management:

  • IdentityClaim and IdentityTier types
  • CreateClaim() - Generate new claims
  • SerializeClaim() - Deterministic encoding matching on-chain format
  • SignClaim() - Ed25519 signing
  • VerifyClaim() - Signature verification
  • Test utilities for generating test claims

Commit 6: Unit Tests

Hash: 9b2bafd

Added comprehensive unit tests:

  • Issuer authorization management tests
  • Tier limits configuration tests
  • Risk thresholds configuration tests
  • Default identity query tests
  • Effective limit calculation tests
  • Limit enforcement tests in lock_funds() and release_funds()
  • Tests for transactions within and exceeding limits

Commit 7: Documentation

Hash: eb5dffb

Created comprehensive documentation:

  • IDENTITY_LIMITS.md - Architecture, usage guide, and troubleshooting
  • backend/internal/identity/README.md - Go package documentation
  • Configuration examples
  • Integration examples for KYC providers
  • Security considerations and best practices

Key Components

On-Chain (Soroban/Rust)

Files:

  • soroban/contracts/escrow/src/identity.rs - Identity types and helper functions
  • soroban/contracts/escrow/src/lib.rs - Contract implementation with identity functions
  • soroban/contracts/escrow/src/identity_test.rs - Unit tests

Key Functions:

  • Admin: set_authorized_issuer, set_tier_limits, set_risk_thresholds
  • User: submit_identity_claim, get_address_identity, get_effective_limit, is_claim_valid
  • Internal: enforce_transaction_limit, verify_claim_signature, calculate_effective_limit

Off-Chain (Go)

Files:

  • backend/internal/identity/claims.go - Claim creation, signing, and verification
  • backend/internal/identity/test_utils.go - Test utilities

Key Functions:

  • CreateClaim - Generate new identity claims
  • SignClaim - Sign claims with Ed25519
  • VerifyClaim - Verify claim signatures
  • SerializeClaim - Deterministic serialization

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                   Identity-Aware Limits System                   │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  Off-Chain (Go):                                                │
│  ┌──────────────────┐         ┌──────────────────┐            │
│  │  KYC Provider    │────────▶│  Claim Issuer    │            │
│  │  (Didit, etc.)   │         │  (Backend)       │            │
│  └──────────────────┘         └────────┬─────────┘            │
│                                         │                        │
│                                         │ Signs Claims           │
│                                         ▼                        │
│                              ┌──────────────────┐               │
│                              │  Identity Claim  │               │
│                              │  + Signature     │               │
│                              └────────┬─────────┘               │
│                                       │                          │
│  ─────────────────────────────────────┼──────────────────────  │
│                                       │ Submit                   │
│  On-Chain (Soroban):                  ▼                          │
│  ┌────────────────────────────────────────────────────┐         │
│  │           Escrow Contract                          │         │
│  │  ┌──────────────────────────────────────────────┐ │         │
│  │  │  Identity Verification                       │ │         │
│  │  │  - Verify signature                          │ │         │
│  │  │  - Check expiry                              │ │         │
│  │  │  - Store identity data                       │ │         │
│  │  └──────────────────────────────────────────────┘ │         │
│  │  ┌──────────────────────────────────────────────┐ │         │
│  │  │  Limit Enforcement                           │ │         │
│  │  │  - Calculate effective limits                │ │         │
│  │  │  - Enforce on lock_funds                     │ │         │
│  │  │  - Enforce on release_funds                  │ │         │
│  │  └──────────────────────────────────────────────┘ │         │
│  └────────────────────────────────────────────────────┘         │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

Identity Tiers and Default Limits

Tier Level Default Limit Description
Unverified 0 100 tokens Default tier, no KYC
Basic 1 1,000 tokens Basic verification
Verified 2 10,000 tokens Full verification
Premium 3 100,000 tokens Enhanced verification

Risk-Based Adjustments

  • Low Risk (0-69): Standard tier limits apply
  • High Risk (70-100): Limits reduced by risk multiplier (default 50%)

Formula: effective_limit = tier_limit * (risk_multiplier / 100)

Claim Lifecycle

  1. Off-Chain: KYC provider verifies user identity
  2. Off-Chain: Backend creates and signs identity claim
  3. User: Receives signed claim
  4. On-Chain: User submits claim to contract
  5. On-Chain: Contract verifies signature and issuer authorization
  6. On-Chain: Contract stores tier and risk score
  7. On-Chain: Limits enforced on all transactions
  8. On-Chain: Expired claims revert to unverified tier

Security Features

  • Ed25519 Signatures: Cryptographic proof of claim authenticity
  • Issuer Authorization: Only trusted issuers can sign valid claims
  • Expiry Timestamps: Claims have limited validity period
  • Signature Verification: Any tampering invalidates signature
  • No PII On-Chain: Only tier and risk score stored
  • Event Logging: All actions logged for audit

Testing

Unit Tests

  • 10+ test cases covering all major functionality
  • Tests for issuer management, limits, queries, and enforcement
  • Edge cases: unverified users, expired claims, boundary values

Test Utilities

  • Go package includes test key generation
  • Helper functions for generating valid test claims
  • Signature verification testing

Configuration

Default Configuration

// Tier Limits (in stroops, 7 decimals)
unverified: 100_0000000      // 100 tokens
basic:      1000_0000000     // 1,000 tokens
verified:   10000_0000000    // 10,000 tokens
premium:    100000_0000000   // 100,000 tokens

// Risk Thresholds
high_risk_threshold: 70      // Risk score >= 70 is high risk
high_risk_multiplier: 50     // High risk users get 50% of tier limit

Customization

All limits and thresholds can be updated by contract admin without redeployment.

Integration Example

Off-Chain (Go)

// Create claim
claim, _ := identity.CreateClaim(
    userAddress,
    identity.TierVerified,
    25, // risk score
    30 * 24 * time.Hour, // 30 days
)

// Sign claim
signature, _ := identity.SignClaim(claim, issuerPrivateKey)

// Return to user

On-Chain (Rust)

// Submit claim
client.submit_identity_claim(&claim, &signature, &issuer_pubkey);

// Query effective limit
let limit = client.get_effective_limit(&address);

// Lock funds (limit enforced automatically)
client.lock_funds(&depositor, &bounty_id, &amount, &deadline);

Future Enhancements

Potential improvements:

  • Multiple concurrent claims per address
  • Time-based limits (daily/weekly)
  • Graduated limits based on transaction history
  • Automated claim renewal
  • Multi-signature claim issuance
  • Claim revocation mechanism

Deployment Checklist

  • Deploy contract with admin address
  • Set initial tier limits
  • Set risk thresholds
  • Authorize initial claim issuer(s)
  • Configure backend with issuer private key
  • Test claim creation and submission
  • Verify limit enforcement
  • Monitor events and logs

Trust Assumptions

  1. Issuer Trust: Authorized issuers perform proper KYC verification
  2. Admin Trust: Contract admin authorizes only legitimate issuers
  3. Signature Security: Ed25519 is cryptographically secure
  4. Time Accuracy: Ledger timestamps are accurate for expiry checks

Privacy Guarantees

  • No personal information stored on-chain
  • Only tier and risk score are public
  • KYC data remains with provider
  • Claims can be verified without revealing identity

Compliance Benefits

  • Regulatory compliance through tiered limits
  • Risk management via risk scores
  • Audit trail via event logging
  • Flexible configuration for different jurisdictions
  • No on-chain PII storage

Conclusion

The identity-aware limits feature successfully implements a robust system for enforcing transaction limits based on off-chain identity verification. The implementation includes:

  • ✅ Complete on-chain contract functionality
  • ✅ Off-chain helper library in Go
  • ✅ Comprehensive unit tests
  • ✅ Detailed documentation
  • ✅ Security considerations
  • ✅ Integration examples
  • ✅ 7 well-structured commits

The system is ready for deployment and integration with KYC providers.