Calculating Reputations with Brevis

The Reputation Hook Contract Project integrates with Brevis Zero-Knowledge (ZK) Computation to securely calculate user reputations in a decentralized and private manner. The interaction begins when the Reputation Hook captures user activity, processes it, and subsequently queues it for Reputation Logic. From there, a batch of updates is handled through Chainlink Automation, and the data is sent to Brevis for processing using the Hamming Distance algorithm to compute reputation scores.

Flow of Reputation Calculation

1. Reputation Hook Records User Activity:

  • The Reputation Hook tracks user actions such as liquidity provision, swaps, and other interactions in the Uniswap V4 pools. These activities are linked to the reputation system, influencing a user’s score.

  • Example:

    reputationLogic.queueReputationUpdate(userAction)
  • This step queues the activity in the Reputation Logic Contract.

2. Reputation Logic and Queuing:

  • The Reputation Logic contract acts as a processing hub, where all user actions are aggregated into an update queue. These actions are stored until they reach a batch size or the Chainlink Automation triggers the batch process based on a time interval.

  • This ensures that multiple updates can be processed together, saving on gas fees and computational costs.

  • Example Queue Check:

    reputationLogic.getUpdateQueueLength();
  • Chainlink Automation regularly checks the queue, batching the updates when conditions are met.

3. Batching and Signaling to Brevis ZK:

  • Once a batch is ready, Chainlink Automation triggers the performUpkeep function, which processes the update queue into batches. These batches are then sent to Brevis Zero-Knowledge Computation for reputation score calculation.

  • Each batch contains key user metrics, including swap details, liquidity changes, token balances, and other pool-related metrics.

  • Example Log:

    ReputationUpdateBatchEmitted(batchId: ..., nonce: ..., users: ..., updatesToProcess: ...)
    ReputationOracle.initiateReputationUpdateBatch()

4. Brevis Zero-Knowledge Computation:

  • Brevis receives the batched data and processes the reputation scores using the Hamming Distance algorithm. This ensures that user activity is processed privately and securely, without revealing sensitive information about individual transactions.

  • Brevis uses zero-knowledge proofs to calculate and validate the results, ensuring the accuracy of reputation scores without leaking any private data to third parties.

5. Hamming Distance and Its Role in Reputation Calculation

In this Proof of Concept (PoC), Brevis employs the Hamming Distance algorithm to compute reputation scores. The Hamming Distance is a metric used to measure the difference between two strings of equal length, often used in cryptography and error detection.

Hamming Distance wikipedia

5.1. Hamming Distance in Reputation Calculation:

  • The algorithm compares users' current behavior with historical data to determine how their actions deviate from an established baseline. The more a user’s behavior deviates from the expected or ideal behavior, the higher the "distance" in terms of reputation score adjustment.

  • For example, a user who consistently provides liquidity and follows favorable behaviors will have a lower Hamming Distance (indicating positive reputation), whereas a user with inconsistent or negative actions (like pulling liquidity during volatility) will have a higher Hamming Distance.

5.2. How Hamming Distance Works:

  • Input: Two equal-length strings (or vectors) representing a user's behavior patterns, current activities, and historical data.

  • Process: The Hamming Distance is calculated by counting the number of positions where the corresponding symbols differ between the two strings.

  • Output: The distance value reflects the level of deviation, which is then used to adjust the user's reputation score.

Example: Assume two binary sequences represent two users' behaviors:

  • User A: 1101 0010 1011

  • User B: 1101 0001 1010

The Hamming Distance between these two sequences is 2 because they differ in two positions.

  • This deviation is interpreted by Brevis to adjust reputation: a smaller distance means more consistent, positive actions, while a larger distance indicates less favorable behavior.

5.3. Why Use Hamming Distance?

  • Simple and Efficient: It allows a fast and gas-efficient calculation, which is crucial for real-time systems like Uniswap V4 pools.

  • Quantifies User Behavior: The Hamming Distance offers a clear and quantifiable measure of how much a user’s behavior deviates from established norms.

  • Suitable for Zero-Knowledge Computation: As a lightweight, easy-to-verify metric, it’s well-suited for use in Zero-Knowledge Proofs, ensuring that reputation calculations can be verified without revealing user data.

Example Flow from Hook to Brevis:

  1. User Activity Tracked in Uniswap V4 pools (e.g., swapping or liquidity provision).

  2. Reputation Logic queues the update, and Chainlink Automation initiates the batch process.

    ReputationLogic.performUpkeep()
  3. Batch Sent to Brevis via the Reputation Oracle, signaling for reputation computation.

    ReputationOracle.initiateReputationUpdateBatch()
  4. Brevis computes the reputation scores using Hamming Distance.

    • Data privacy is maintained throughout the process using Zero-Knowledge Proofs.

  5. Reputation Oracle updates user reputation scores on-chain based on Brevis's computation.

    emit ReputationUpdateBatchProcessed()

Last updated