HashReceiver

The HashReceiver circuit is intended for handling and validating the transfer of amounts to a receiver. It creates hashed versions of the amount transferred and the balance of the receiver before and after the transfer.

Input Signals

The circuit takes the following inputs:

  1. amount: The amount to be transferred to the receiver.

  2. receiverBalanceBeforeTransfer: The receiver's balance before the transfer occurs.

signal input amount;  
signal input receiverBalanceBeforeTransfer;

Output Signals

The circuit outputs the following signals:

  1. receiverBalanceBeforeTransferHash: The hash of the receiver's balance before the transfer occurs.

  2. receiverBalanceAfterTransferHash: The hash of the receiver's balance after the transfer has occurred.

  3. amountHash: The hash of the amount that is transferred.

signal output receiverBalanceBeforeTransferHash;
signal output receiverBalanceAfterTransferHash;
signal output amountHash;

Components

The circuit utilizes the following components:

  • comp1: A comparator to ensure that the amount is greater than or equal to zero.

component comp1 = GreaterEqThan(252);
comp1.in[0] <== amount;
comp1.in[1] <== 0;
comp1.out === 1;
  • hashAmount: A Poseidon hashing function to create a hash of the amount.

component hashAmount = Poseidon(1);
hashAmount.inputs[0] <== amount;
amountHash <== hashAmount.out;
  • hashBeforeBalance: A Poseidon hashing function to create a hash of the receiver's balance before the transfer.

component hashBeforeBalance = Poseidon(1);
hashBeforeBalance.inputs[0] <== receiverBalanceBeforeTransfer;
receiverBalanceBeforeTransferHash <== hashBeforeBalance.out;
  • hashAfterBalance: A Poseidon hashing function to create a hash of the receiver's balance after the transfer.

component hashAfterBalance = Poseidon(1);
hashAfterBalance.inputs[0] <== receiverBalanceBeforeTransfer + amount;
receiverBalanceAfterTransferHash <== hashAfterBalance.out;

External Circuit Inclusions

The circuit includes poseidon and comparators circuits from the circomlib library.

include "../../node_modules/circomlib/circuits/poseidon.circom";
include "../../node_modules/circomlib/circuits/comparators.circom";

Main Component

The main component of this circuit file is the HashReceiver template.

component main = HashReceiver();

The HashReceiver circuit is used primarily for creating hashed versions of the amount being transferred and the receiver's balance before and after the transfer. This can be used for transaction verification and integrity checks within your application.

Last updated