npm package: @fubuloubu/silencer
Description: GunClear's Zero Knowledge Proof circuit library
Latest version: 0.1.0-alpha.2

# Silencer

GunClear's Zero Knowledge Proof circuit library

**NOTE**: Currently keep private (DO NOT PUBLISH!)

## API

Please see the
[GunClear Transaction Specification](https://gitlab.com/zatoichi-labs/gunclear/specification/-/blob/master/Transaction.md)
for further details about the transaction specifications.

## CLI Usage

1. Install
```bash
$ make rust-cli
```

1. Generate proving and verifying keys for all circuits
```bash
$ silencer-cli generate membership
$ silencer-cli generate receive
$ silencer-cli generate send
```

1. Generate membership proofs
```bash
$ silencer-cli prove membership \
        # Account Address (20 bytes) \
        0000000000000000000000000000000000000001 \
        # Account status (31 bytes) \
        00000000000000000000000000000000000000000000000000000000000001 \
        # Required status (31 bytes) \
        # NOTE: Must be a subset of the previous \
        00000000000000000000000000000000000000000000000000000000000001 \
        # Merkle Witness (20 x 32 bytes) \
        00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Parameter: BLINDING_FACTOR
d8109018a5fd204b190349d380b9ac7cd095f56c708ec2c9100beb6c00a472
# Randomly generated view key

Parameter: ACCOUNT_VIEWHASH
f36efdc79abd8d0f790951de77761a8fb9a32a5c809fa23b3406e38426d9d2d9
# blake2s(12B + ACCOUNT_ADDRESS + 1B + BLINDING_FACTOR)

Parameter: MEMBERSHIP_ROOTHASH
732a66896a8ea88901c261a0a04dbf178437e1422876129870c79ac3790206d3
# calc_root(ACCOUNT_ADDRESS, blake2s(1B + ACCOUNT_STATUS + 32B), MERKLE_PROOF)

Parameter: MEMBERSHIP_PROOF
a02712ddc9d4bca044560f8b667a71cb8f27913e150e87cf70bea2da927a8c55e10c8c8096576ae76915267043ecdb7b82bd514219d9eac9d2a0f99e1f6acd435c5ffca0faf0bfb7583ad4ec2a6d7b6ffe13bf7190e3f0c9602b2fc588728bc218a2d3b0556ba3a31df76264df545b2741f8facf10051be35ffaf58fb08eac74d6f08f056c4a79005bee6408bf085664b1a85c3b04fd3973e7989047c5d860d16c9533c65a3ba15b9d6a0a2c3aea2f8d7786dd7a5b035acf929764bf0217c25d
```

1. Generate creation proofs
```bash
$ silencer-cli prove creation \
        # Serial Number (31 bytes) \
        00000000000000000000000000000000000000000000000000000000000001 \
        # Creator Account Address (20 bytes) \
        0000000000000000000000000000000000000001 \
        # Creator Membership View Key (31 bytes) \
        d8109018a5fd204b190349d380b9ac7cd095f56c708ec2c9100beb6c00a472
Created Parameter: FIREARM_VIEWKEY
ba7398ec8a8639cde932382b65605a57fd30927ebba9bf0396d7065d864f47
# Randomly generate spend key

Created Parameter: TOKEN_UID
2290fa0e12146d19dd51fee1b0022512fd83a709cd55ef2ca2536ea99b7c4a44
# blake2s(1B + FIREARM_SERIAL + 1B + FIREARM_VIEWKEY)

Created Parameter: CREATION_PROOF
a04a0cbef26c3ebb57f6eca8d6f390d647091714bb7a4ba0f4f7c324bd888c671a99338ed50252378c070c48301e7160aec9fdf070a7d48162419adf8494073f0ea7eb36ef782e25384313268f6e82f5ae1a0d073daccc7f6dfbc23cf5a1e77d192b84d5a228f6a51f8de39ced97520b8695c34190419a0210351b2a6ca3925737ddf1cb1a500a67c91af9e49fc8374cad5804862dd97ea8670355a05d17b453703ba2227a91a0f18ff2c9ef13efc84aa8b41b5b3c315ce4cf97b23438c14e96
```

1. Generate receiver proofs
```bash
$ silencer-cli prove receive \
        # Token ID (32 bytes) \
        0000000000000000000000000000000000000000000000000000000000000001 \
        # Receiver Account Address (20 bytes) \
        0000000000000000000000000000000000000001 \
        # Receiver Membership View Key (31 bytes) \
        d8109018a5fd204b190349d380b9ac7cd095f56c708ec2c9100beb6c00a472 \
        # Sender Account Address (20 bytes) \
        0000000000000000000000000000000000000002
Created Parameter: SPEND_COMMITMENT
5db63d6509d9d3aac8a92dd73f842c129c56cddc53276b248591f4bbd77f25
# Randomly generate spend key

Created Parameter: NEW_TXNHASH
271d2adc850883af4e7428213b719961f0da8cfebaec98f3d30cd4bc080bff98
# blake2s(
#   blake2s(12B + SENDER_ADDRESS + 12B + RECEIVER_ADDRESS) +
#   blake2s(TOKEN_UID + 1B + SPEND_COMMITMENT)
# )

Created Parameter: RECEIVE_PROOF
a7c816f9ea55de5e2ea2d7bd7c9d2a4b6608e20045be19a7fa9e8916192d9a06da6264f151c252cd9a902a065e19fae095a35787ae394a999899da2bcc0cc1eb941a401d175ed2dc0ceb2141510d976fd1230350cffcb95ab64ca1a3b89b55b80b789d45327de1cc8237e38efaa11edbc45884b60850b740b4ce07670cd9acd710ede0c3d9747d4f92c3927673cdaac685d7e5344fbcf7cddb65264f728c92804e978b30a205131093275288b47916f7cac46fe6615ce212be528c8ffed8535a
```

1. Generate spend proofs
```bash
$ silencer-cli prove send \
        # Token ID (32 bytes) \
        0000000000000000000000000000000000000000000000000000000000000001 \
        # Sender Account Address (20 bytes) \
        0000000000000000000000000000000000000002 \
        # Sender Membership View Key (31 bytes) \
        f9f76696de5111290c8ea8a4b9d58a421b5c5467b0baa59ddabb8815d9973f \
        # Previous Account Address (20 bytes) \
        0000000000000000000000000000000000000000 \
        # Sender's Token Spend Key \
        00000000000000000000000000000000000000000000000000000000000042 \
        # New Transaction Hash \
        271d2adc850883af4e7428213b719961f0da8cfebaec98f3d30cd4bc080bff98
Created Parameter: OLD_TXNHASH
920ddefd6adf454ec4fd3fd9799885eedde123d025ac1c749a6f7dac80a95fe6
# blake2s(
#   blake2s(12B + PREV_ADDRESS + 12B + SENDER_ADDRESS) +
#   blake2s(TOKEN_UID + 1B + SPEND_COMMITMENT)
# )

Created Parameter: TRANSFERHASH
94425f945953a52cee371766b08d6d13f1466681f2709f4fc3c242ec22397d71
# blake2s(OLD_TXNHASH + NEW_TXNHASH)

Created Parameter: SEND_PROOF
8d86e6f6cff329a4eb9648320ac8fdd1b3cc8d04f56f3bfbb097b733dd8537f7a580af148c2d3d0780e7e24a1e5af34c8ad952e5e7dc8fc251c654ea27df86207cea6653bb58bd3d84f8a386ae47bacbf77c3d1703c52985424d1b79de3fbee603d3cf7161c62c144661ab3b005215100afd590bd29f9a156e5b0eee0376c96317d6556f06d962539d45e993c328e19090daa7313c55ac04e5e3363fc00a6d97e2a1e5cbda4f78b35073028788f192d74102c54bae14e72be93176cce1d287d3i
```

7. Validate proofs
```bash
$ silencer-cli verify membership \
        88bf94f6fedb69fd69c9f4640e1cc541420bbd7314f6372bce0d0e4a7e466423 \
        00000000000000000000000000000000000000000000000000000000000001 \
        b97f95f12c99194de662562670212b2beec17d5e6a4c986d72e1919222201844 \
        b9d2013f8ca8615120505597e846ef1c5970529702bf87224177b64b52b58fad23cb1f7994c483b2f54b42ab1f8cb9ecb38686e9ee95fb6b15e2be3b868842ad7875660e9da070eaa677597bb4712c380e29636b469ee1796ffd6b9dd5a891ad0757467140e38497de4585f1b1da26ce0859f8d63fe699bc5a069b1c3c630e494cf92ca90418d04ef9a7b59ceb645f0ba41eb94a20ad834e40532788366ea705e5895941d4c5cc8714679ebe88182daffb1295ecd55d86b371eb40c864ad3e4e
Proof Valid: true
$ silencer-cli verify send \
        0000000000000000000000000000000000000000000000000000000000000001 \
        13220e4c61e1173c1b00efc2553a1f1dcac62af4d600bb0b064f194ac8099673 \
        920ddefd6adf454ec4fd3fd9799885eedde123d025ac1c749a6f7dac80a95fe6 \
        271d2adc850883af4e7428213b719961f0da8cfebaec98f3d30cd4bc080bff98 \
        94425f945953a52cee371766b08d6d13f1466681f2709f4fc3c242ec22397d71 \
        8d86e6f6cff329a4eb9648320ac8fdd1b3cc8d04f56f3bfbb097b733dd8537f7a580af148c2d3d0780e7e24a1e5af34c8ad952e5e7dc8fc251c654ea27df86207cea6653bb58bd3d84f8a386ae47bacbf77c3d1703c52985424d1b79de3fbee603d3cf7161c62c144661ab3b005215100afd590bd29f9a156e5b0eee0376c96317d6556f06d962539d45e993c328e19090daa7313c55ac04e5e3363fc00a6d97e2a1e5cbda4f78b35073028788f192d74102c54bae14e72be93176cce1d287d3
Proof Valid: true
$ silencer-cli verify receive \
        0000000000000000000000000000000000000000000000000000000000000001 \
        f36efdc79abd8d0f790951de77761a8fb9a32a5c809fa23b3406e38426d9d2d9 \
        271d2adc850883af4e7428213b719961f0da8cfebaec98f3d30cd4bc080bff98 \
        a7c816f9ea55de5e2ea2d7bd7c9d2a4b6608e20045be19a7fa9e8916192d9a06da6264f151c252cd9a902a065e19fae095a35787ae394a999899da2bcc0cc1eb941a401d175ed2dc0ceb2141510d976fd1230350cffcb95ab64ca1a3b89b55b80b789d45327de1cc8237e38efaa11edbc45884b60850b740b4ce07670cd9acd710ede0c3d9747d4f92c3927673cdaac685d7e5344fbcf7cddb65264f728c92804e978b30a205131093275288b47916f7cac46fe6615ce212be528c8ffed8535a
Proof Valid: true
$ silencer-cli verify creation \
        271d2adc850883af4e7428213b719961f0da8cfebaec98f3d30cd4bc080bff98 \
        f36efdc79abd8d0f790951de77761a8fb9a32a5c809fa23b3406e38426d9d2d9 \
        00000000000000000000000000000000000000000000000000000000000001 \
        a04a0cbef26c3ebb57f6eca8d6f390d647091714bb7a4ba0f4f7c324bd888c671a99338ed50252378c070c48301e7160aec9fdf070a7d48162419adf8494073f0ea7eb36ef782e25384313268f6e82f5ae1a0d073daccc7f6dfbc23cf5a1e77d192b84d5a228f6a51f8de39ced97520b8695c34190419a0210351b2a6ca3925737ddf1cb1a500a67c91af9e49fc8374cad5804862dd97ea8670355a05d17b453703ba2227a91a0f18ff2c9ef13efc84aa8b41b5b3c315ce4cf97b23438c14e96
Proof Valid: true
```

NOTE: Yes, the proofs do indeed fail if not consistent:
```bash
$ silencer-cli verify membership \
        $(cat ./sender-view.hash) \
        42 \  # NOTE: Must be different from the number entered earlier
        $(cat ./merkle-root.hash) \
        $(cat ./sender-membership.proof)
Proof Valid: false
```