HashSender

The HashSender circuit is designed to process and validate transfers from a sender, creating hashed versions of the amount transferred, the balance of the sender before and after the transfer, a nonce for transaction uniqueness, and a combined identifier hash.

Input Signals

The circuit accepts the following inputs:

  1. sender: The sender of the transaction.

  2. senderBalanceBeforeTransfer: The balance of the sender before the transaction.

  3. amount: The amount to be transferred.

  4. nonce: A unique identifier for each transaction.

signal input sender;
signal input senderBalanceBeforeTransfer;
signal input amount;  
signal input nonce;

Output Signals

The circuit outputs the following signals:

  1. senderBalanceBeforeTransferHash: The hash of the sender's balance before the transfer occurs.

  2. senderBalanceAfterTransferHash: The hash of the sender's balance after the transfer has occurred.

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

  4. nonceVerification: The nonce input passed straight through for verification.

  5. idHash: The hash of a combination of sender, sender balance before transfer, amount, and nonce.

signal output senderBalanceBeforeTransferHash;
signal output senderBalanceAfterTransferHash;
signal output amountHash;
signal output nonceVerification;
signal output idHash;

Components

The circuit incorporates the following components:

  • comp1: A comparator ensuring 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;
  • comp2: A comparator checking if the senderBalanceBeforeTransfer is greater than or equal to the amount.

component comp2 = GreaterEqThan(252);
comp2.in[0] <== senderBalanceBeforeTransfer;
comp2.in[1] <== amount;
comp2.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 sender's balance before the transfer.

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

component hashAfterBalance = Poseidon(1);
hashAfterBalance.inputs[0] <== senderBalanceBeforeTransfer - amount;
senderBalanceAfterTransferHash <== hashAfterBalance.out;
  • hashId: A Poseidon hashing function to create a hash of a combination of sender, sender balance before transfer, amount, and nonce.

component hashId = Poseidon(4);
hashId.inputs[0] <== sender;
hashId.inputs[1] <== senderBalanceBeforeTransfer;
hashId.inputs[2] <== amount;
hashId.inputs[3] <== nonce;
idHash <== hashId.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 HashSender template.

component main = HashSender();

The HashSender circuit is primarily used for hashing important aspects of a transaction from a sender, which includes the amount transferred, the sender's balance before and after the transfer, a nonce for each transaction, and a combined identifier hash. This allows for secure, reliable transaction verification and integrity checks within your application.

Last updated