# 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.

```circom
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.

```circom
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.

```circom
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`.

```circom
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`.

```circom
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.

```circom
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.

```circom
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.

```circom
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.

```circom
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.

```circom
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.notcentralised.com/circuits/hashsender.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
