google-differential-privacy

repository·main·Indexed 25 days ago

https://github.com/google/differential-privacy

A collection of libraries and frameworks for implementing differential privacy (DP) in Go, C++, Java, Python, Kotlin, and Scala. It provides low-level mathematical building blocks, high-level data pipelines, and Privacy Loss Distributions (PLDs) for accounting tools. The project includes a PostgreSQL extension (anon_func) that provides epsilon-DP aggregate functions such as ANON_COUNT, ANON_SUM, ANON_AVG, ANON_VAR, ANON_STDDEV, and ANON_NTILE.

Tokens
30K
Snippets
81
Records
144
Agent score
83%

What's inside google-differential-privacy

  1. Overview of Privacy on Beam

    main

    Privacy on Beam is an end-to-end differential privacy solution built on Apache Beam. It is designed to be accessible to developers without deep differential privacy expertise by automating essential steps such as noise addition, partition selection, and contribution bounding.

    Note: Privacy on Beam is currently only available in Go.

  2. Overview of Differential Privacy tools

    main

    This repository provides several tools for generating ε- and (ε, δ)-differentially private (DP) statistics. The tools are categorized into high-level frameworks and low-level building blocks:

    • Privacy on Beam: An end-to-end DP framework for Go built on Apache Beam.
    • PipelineDP4j: An end-to-end DP framework for JVM languages (Java, Kotlin, Scala) supporting Apache Beam and Apache Spark.
    • PipelineDP: An end-to-end DP framework for Python (a collaboration with OpenMined).

    Low-Level Building Blocks

    • DP Building Block Libraries: Available in C++, Go, and Java. These implement basic noise addition primitives and DP aggregations.

    Specialized Tools

    • Differential Privacy Accounting Library (Python): Used for tracking privacy budget.
    • DP Auditorium (Python): A library for auditing differential privacy guarantees.
    • ZetaSQL CLI: A command line interface for running differentially private SQL queries using ZetaSQL.
    • Stochastic Tester (C++): Used to catch regressions in DP properties.
  3. Overview of Differential Privacy in this library

    main

    This library provides a collection of algorithms for computing differentially private statistics over data. The algorithms are designed to be used without requiring deep mathematical knowledge, as the mathematical complexity is encapsulated within the algorithms themselves.

    Differential privacy manages the tradeoff between the accuracy of aggregations (e.g., mean) and the privacy of individual records. Unlike other anonymization schemes, differential privacy degrades gracefully as more data is released.

  4. Overview of DP-Auditorium components

    main

    DP-Auditorium is a library for auditing differential privacy guarantees. The core components are:

    • Testers (dp_auditorium/testers/): Contains PropertyTesters that check if a privacy guarantee holds on a fixed pair of datasets.
    • Generators (dp_auditorium/generators/): Contains DatasetGenerators that output pairs of neighboring datasets (e.g., under the add/remove relation).
    • Mechanisms (dp_auditorium/mechanisms/): Contains examples of private and non-private mechanisms.
    • Runner (privacy_test_runner.py): A module that specializes a tester and a generator to conduct tests on datasets' trials.
    • Examples (dp_auditorium/examples/): Contains usage examples combining these tools.
  5. Overview of Differential Privacy Accounting tools

    main

    The Differential Privacy Accounting tools provide implementations of Privacy Loss Distributions (PLDs). These tools help compute accurate estimates of the total privacy budget (ε, δ) across multiple executions of differentially private aggregations.

    Supported mechanisms include:

    • Laplace mechanisms
    • Gaussian mechanisms
    • Randomized response
  6. Overview of Differential Privacy Accounting

    main

    The dp_accounting library provides tools for tracking differential privacy budgets. It allows you to describe complex mechanisms (like Laplace, Gaussian, and subsampling mechanisms) and their compositions using DpEvent classes. The PrivacyAccountant classes can then ingest these events to calculate the ε (epsilon) and δ (delta) of the composite mechanism.

    Supported accounting methods include:

    • Privacy Loss Distributions (PLDs)
    • RDP (Rényi Differential Privacy) accounting

    Requirements:

    • Python version >= 3.10
    • Tested on Linux
  7. Use PipelineDP4j in JVM projects

    main
    PipelineDP4j is an end-to-end differential privacy solution for the JVM that supports distributed data processing frameworks like Apache Beam and Apache Spark. It automates essential differential privacy steps such as noise addition, partition selection, and contribution bounding. It is compatible with Java, Kotlin, and Scala.
  8. Understand the DP Building Block Libraries attack model

    main

    The DP Building Block Libraries are designed to provide differentially private output under specific security assumptions. To use these libraries safely, developers must ensure their higher-level framework addresses the following constraints:

    Core Assumptions

    • Trusted Compute Nodes: The library must run on trusted hardware. If an attacker controls processes on the same node, they may access raw user data directly, bypassing DP protections.
    • Batch Mode Execution: The library is intended for batch processing where outputs are eventually published to a wider audience.
    • No Direct User Awareness: The library does not manage 'users'. It is the responsibility of the consuming framework to handle user-level logic, such as limiting the number of contributions per user to prevent privacy leakage.
    • Non-Interactive Use: The library is not designed for interactive settings (e.g., allowing an untrusted analyst to run arbitrary queries).

    Attacker Capabilities

    • Prior Knowledge: An attacker may know a subset of raw data (including their own contributions) or even most of the dataset. The DP parameters epsilon and delta must be configured to ensure the output does not reveal specific individual contributions.
    • Data Injection: An attacker may forge a large number of contributions. Mitigations like rounding or enforcing contribution limits should be implemented in the application logic.
    • Order of Events: An attacker may control the sequence of data passed to the library. The DP library is designed to protect against attacks targeting floating-point arithmetic non-associativity related to data ordering.
    • Side Channels: The model assumes the attacker cannot observe memory consumption, CPU utilization, network usage, timing, or the state of the random number generator.
  9. Load the anon_func extension in Postgres

    main

    After starting the container, connect to the database using psql and load the differential privacy extension by executing the CREATE EXTENSION command.

    1. Connect to the instance:
    psql -U postgres -h localhost -p 5432
    1. Use the password password when prompted.
    2. Load the extension:
    CREATE EXTENSION anon_func;
  10. Handle multiple contributions per partition via pre-aggregation

    main

    For algorithms like BoundedSum, the library assumes maxContributionsPerPartitions is 1. If a single privacy unit (e.g., a visitor) can contribute multiple times to the same partition (e.g., multiple visits in one day), you should pre-aggregate those values manually before calling addEntry().

    This prevents the library from overestimating sensitivity and adding unnecessary noise. When pre-aggregating, ensure you adjust the upper bound of your BoundedSum to reflect the maximum possible cumulative amount a user can contribute to a single partition.

    // For each visitor, pre-aggregate their spending for the day.
    Map<String, Integer> visitorToDaySpending = new HashMap<>();
    for (Visit v : boundedVisits.getVisitsForDay(d)) {
      String visitorId = v.visitorId();
      if (visitorToDaySpending.containsKey(visitorId)) {
        int newAmount = visitorToDaySpending.get(visitorId) + v.eurosSpent();
        visitorToDaySpending.put(visitorId, newAmount);
      } else {
        visitorToDaySpending.put(visitorId, v.eurosSpent());
      }
    }
    
    // Then use the aggregated values in BoundedSum with an appropriate upper bound
    private static final int MAX_EUROS_SPENT = 65; // Adjusted for cumulative spending
    ...
    BoundedSum dpSum =
        BoundedSum.builder()
            .epsilon(LN_3)
            .maxPartitionsContributed(MAX_CONTRIBUTED_DAYS)
            .lower(MIN_EUROS_SPENT)
            .upper(MAX_EUROS_SPENT)
            .build();