HOME CONCEPT GRANTS BLOG COMMUNITY

[ATP + vetKeys] Privacy-preserving Feature Implementation

Build privacy-preserving trading on Internet Computer using ATP and vetKeys. This grant supports implementing encrypted order functionality that enables secure, private asset exchanges between participants without exposing trading intentions publicly.

By Mycel - 2025-06-15

Prerequisites

Technical Prerequisites

  • Internet Computer Development: DFINITY SDK (dfx) and Rust environment
  • ATP Understanding: Basic knowledge of account creation, transfer, and activation
  • vetKeys Proficiency: Understanding of encrypted key derivation concepts

Knowledge Requirements

  • Rust programming for IC canisters
  • Basic cryptographic concepts (encryption/decryption)
  • Understanding of P2P trading flows (order creation, asset verification, settlement)

Overview

As of the ATP implementation at the May 21, 2025 release, ATP user IDs and order contents are publicly exposed. While this is acceptable for most DEX use cases where order information between parties is publicly available, the current implementation is insufficient when implementing privacy-focused products or facilitating peer-to-peer asset exchanges. This grant aims to deploy functionality that enables intent-based trading while ensuring privacy by concealing order contents using ATP and vetKeys.

This grant provides support for implementations that demonstrate how ATP and vetKeys work together to enable privacy-protected trading between two participants.

Simple Flow

  1. Participant A creates an order and locks assets in an ATP account
  2. Participant A encrypts order details using vetKeys
  3. Participant A sends the encrypted order directly to Participant B
  4. Participant B decrypts the order, verifies A’s locked assets, and decides to accept/reject
  5. If accepted, both participants use ATP to execute an atomic asset swap

Key Benefits

  • Order Privacy: Trading intentions remain hidden until shared with specific counterparts
  • Asset Security: ATP handles secure asset locking and atomic transfers
  • No Intermediary: Direct participant-to-participant communication
  • Simple Architecture: Minimal complexity, easy to understand and extend

Goals

  1. Create Working Implementation

    • Build a functional demo of privacy-protected trading features using ATP + vetKeys
    • Demonstrate direct communication patterns between participants
    • Prove atomic settlement through ATP account transfers
  2. Developer Education

    • Provide clear Rust code examples for ATP integration
    • Show practical vetKeys usage for order encryption
    • Document the complete flow from order creation to settlement
  3. Reusable Components

    • Create modular code that developers can copy and extend
    • Establish patterns for ATP + vetKeys integration
    • Build foundation for more complex trading systems

Specification

Complete Trading Flow

sequenceDiagram
    participant A as Participant A
    participant C as Canister
    participant B as Participant B
    
    A->>A: 1. Create Order
    A->>A: 2. Encrypt Order using B's Identity (vetKeys)
    A->>C: 3. Submit Encrypted Order
    A->>A: 4. Lock Assets with ATP
    A->>B: 5. Send Order Details
    B->>C: 6. Verify A's Locked Assets
    B->>B: 7. Lock Assets with ATP (if accepting)
    B->>A: 8. Notify Asset Lock Completion
    A->>C: 8. Verify B's Locked Assets
    
    alt Trade Execution
        A->>C: 9a. Withdraw from B's ATP Account
        B->>C: 9b. Withdraw from A's ATP Account
        Note over A,B: Trade Complete
    else Expiration
        A->>C: 10a. Withdraw Original Assets
        B->>C: 10b. Withdraw Original Assets
        Note over A,B: Assets Returned
    end

Step-by-Step Flow Description

Step1. Order Creation (Participant A) A creates an order specifying the desired trade details (offered asset, offered amount, wanted asset, wanted amount, expiration time).

Step 2. Order Encryption using B’s Identity (Participant A) A encrypts the order details using vetKeys with B’s principal identity as the encryption target. Only B can decrypt this order.

Step 3: Order Submission (Participant A) A submits the encrypted order to the canister for storage and reference.

Step 4: Asset Locking with ATP (Participant A) A creates an ATP account and transfers the offered assets in a “locked” state, making them unavailable for other uses but verifiable by others.

Step 5: Order Details Transmission (A to B) A sends order information to B, including encrypted order data and ATP account details for verification.

Step 6: Asset Verification (Participant B) B decrypts the order using their vetKey and verifies that A has actually locked the promised assets in their ATP account.

Step 7: Asset Locking (Participant B) If B accepts the trade, they create their own ATP account and lock the assets that A wants.

Step 8: Asset Verification (Participant A) A verifies that B has locked the correct assets in their ATP account before proceeding with the trade.

Step 9: Trade Execution (Both Parties) Both parties withdraw assets from each other’s transferable ATP accounts, completing the atomic swap.

Step 10: Expiration Handling If the order expires before completion, both parties can withdraw their original assets from their respective ATP accounts.

Key Components

  1. Order Structure

    1. Offered asset and amount
    2. Wanted asset and amount
    3. Expiration timestamp
    4. Creator identity
  2. Privacy Layer (vetKeys)

    1. Order encryption using recipient’s identity
    2. Only intended recipients can decrypt order details
    3. Keeps trading intentions private until shared
  3. Security Layer (ATP)

    1. Asset locking in transferable accounts
    2. Verifiable asset deposits
    3. Atomic settlement mechanism
    4. Automatic expiration handling

Implementation Plan

Month 1: Core Implementation

  • Steps 1-4: Order creation, encryption, and ATP asset locking
  • Steps 5-6: Order sharing and asset verification
  • Basic data structures and vetKeys integration

Month 2: Settlement & Documentation

  • Steps 7-10: Mutual locking, verification, and settlement
  • Expiration handling and asset recovery
  • Complete documentation and demo interface

License

MIT License - Open source for educational use and community development

Funding

Total Budget: $4,000

Deliverables

  1. Rust Canister Code ($2,500)

    • Complete ATP + vetKeys integration example
    • Order encryption/decryption functionality
    • Asset verification and settlement logic
  2. Documentation & Examples ($500)

    • Architecture documentation
    • Code comments and explanations
    • Step-by-step tutorial
    • Trading scenario examples
  3. Simple Demo Interface ($1,000)

    • Basic web frontend showing the complete flow
    • Demonstration of order creation, encryption, and settlement

Resources