### 3 releases

0.0.3 | May 3, 2024 |
---|---|

0.0.2 | Jul 20, 2023 |

0.0.1 | Mar 14, 2023 |

#**169** in Magic Beans

**660** downloads per month

Used in **13** crates
(11 directly)

**MIT**license

34KB

603 lines

# groth16-solana

Groth16 zero-knowledge proof verification with Solana altbn254 syscalls.

Verification takes less than 200,000 compute units.

The syscalls are contained in Solana releases 1.15.0 onwards and yet to be activated on a public network.

Inputs need to be in u8 arrays in big endian.

See functional test as an example how to use this library.

This crate is compatible with Groth16 proofs of circom circuits.

The verifier file can be generated with the java script script from a verifyingkey.json file generated by snarkjs.

## Usage:

`let` `mut` public_inputs_vec `=` `Vec``::`new`(``)``;`
`for` input `in` `PUBLIC_INPUTS``.``chunks``(``32``)` `{`
public_inputs_vec`.``push``(`input`)``;`
`}`
`let` proof_a`:` `G1` `=`
`<`G1 `as` FromBytes`>``::`read`(``&``*``[``&``change_endianness``(``&``PROOF``[``0``..``64``]``)``[``..``]``,` `&``[``0``u8``]``[``..``]``]``.``concat``(``)``)`
`.``unwrap``(``)``;`
`let` `mut` proof_a_neg `=` `[``0``u8``;` `65``]``;`
`<`G1 `as` ToBytes`>``::`write`(``&`proof_a`.``neg``(``)``,` `&``mut` proof_a_neg`[``..``]``)``.``unwrap``(``)``;`
`let` proof_a `=` `change_endianness``(``&`proof_a_neg`[``..``64``]``)``.``try_into``(``)``.``unwrap``(``)``;`
`let` proof_b `=` `PROOF``[``64``..``192``]``.``try_into``(``)``.``unwrap``(``)``;`
`let` proof_c `=` `PROOF``[``192``..``256``]``.``try_into``(``)``.``unwrap``(``)``;`
`let` `mut` verifier `=` `Groth16Verifier``::`new`(`
`&`proof_a`,`
`&`proof_b`,`
`&`proof_c`,`
public_inputs_vec`.``as_slice``(``)``,`
`&``VERIFYING_KEY``,`
`)`
`.``unwrap``(``)``;`
verifier`.``verify``(``)``.``unwrap``(``)``;`

See functional test for a running example how to use this library.

## Create Verifyingkey from snarkjs verifyingKey.json

Use snarkjs to export the verifyingkey as json.

In this repo:

- npm i
- npm run parse-vk

## License

Licensed under Apache License, Version 2.0.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

#### Dependencies

~16–25MB

~420K SLoC