- Initialize repo
yarn initialize
- Pull latest docker images (optional)
docker-compose pull
-
Add
.env
configuration file -
You can use your own generated proving params or copy ones used for testing
./scripts/copy_params.sh
- Start local ganache and deploy contracts
./scripts/deploy.sh
- Start redis
docker-compose up redis
- Start relayer
- Locally
yarn start:dev
- Using docker
docker-compose up relayer
yarn test
/transaction
- submit a transaction to relayer
Recieved:
{
proof, // TX proof
memo, // memo block
txType, // 0 - Deposit, 1 - Transfer, 2 - Withdraw
extraData // Optional nullifier signature for Depost
}
/proof_tx
- proove tx. Use only for tests. Tx proof must be calculated on client side but for now it is slow
Recieved:
{
pub, // public inputs for tx circuit
sec, // secret inputs for tx circuit
}
Returns:
{
inputs: Array<string>;
proof: SnarkProof;
}
/transactions/:limit/:offset
- get transactions at indecies [offset, offset+128 .. offset+limit*128]
and for each return string out_commit+memo
Returns:
(Buffer|null)[]
High-level overview:
- Client fetches all commitments and memo blocks (either from relayer or directly from the blockchain) and decrypts their notes and accounts. All commitments should be stored in local Merkle tree, together with found notes and accounts.
- Client builds a zk-SNARK proof for the transaction using previously fetched notes and the most recent account. Then this proof, together with public inputs, memo block, and optional nullifier signature (used only for deposits), is sent to the relayer.
- Relayer adds a job to the queue. It checks that the tx proof is valid, builds another zk-SNARK proof for tree update, sends tx to the blockchain, and updates the local Merkle tree using sent data. It also locally stores commitment hash (one of the public inputs) and memo messages.
You can use already implemented client to interact with the protocol.
Technical overview of libzeropool-rs
:
-
Client uses IndexedDB as storage for accounts, notes, and Merkle tree nodes.
-
You can create or restore an account via
createAccount
function, providing a secret key and state. -
Then, you can request commitments and memos for previous transactions via
/transactions/:limit/:offset
relayer endpoint. -
Decrypt incoming notes with
decryptNotes
and add them withaddReceivedNote
. Decrypt your accounts withdecryptPair
and add them withaddAccount
. -
Insert received commitments and decoded hashes of leaves in the tree
-
Call
createTx
function, providing correctdeltaIndex
, which is basically the index of the first leaf in the next transaction ((txNum + 1) * 128
). It will generate a tx object. -
If you are making a deposit, generate a signature for the tx nullifier (you can get it from
tx_object.public.nullifier
) and store it. -
Generate a proof for this tx object either with
Proof.tx
method or request it from relayer/proof_tx
(only for testing). -
Send
proof
,memo
(get it fromtx_object.memo
),txType
(0..2
) andextraData
to/transaction
endpoint.
You can check more details in test-e2e
example