This packages contains hash algorithms for use in ZK contracts in Pact, on the Kadena blockchain.
- MiMC (Sponge contstruction version)
- Poseidon
Pact implementation of the MiMC hash for Kadena.
Compatible with Circom's and ZoKrates's Sponge construction with 220 Rounds:
https://github.com/iden3/circomlib/blob/master/circuits/mimcsponge.circom
https://github.com/iden3/circomlibjs/blob/main/src/mimcsponge.js
https://github.com/Zokrates/ZoKrates/tree/develop/zokrates_stdlib/stdlib/hashes/mimcSponge
Constants are generated by keccak256 using the seed mimcsponge
(defun feistel-hash:object (key:integer input:object)
key
: keyinput
: hashing object : {'L:integer 'R:integer}
Returns an hashing object: {'L:integer 'R:integer}
Gas consumption (pact <= 4.7.x):
- 27,697
Gas consumption (pact >= 4.8):
- 5,513
Equivalence:
Library | Function |
---|---|
Circomlib | MiMCFeistel(220) |
CircomlibJS | MIMCSponge.hash() |
ZoKrates Stdlib | mimcFeistel(field xL_in, field xR_in, field k) -> field[2] |
(defun feistel-multi-hash:[integer] (key:integer inputs:[integer] n-outputs:integer)
key
: keyinputs
: input list of integersn-outputs
: Number of outputs integer to return
Returns the hash result as a list of integers.
Gas consumption (pact <= 4.7.x):
- 1 input/1 output: 27,724
- 1 input/10 outputs: 277,160
- 10 inputs/1 output: 277,189
- 10 inputs/10 outputs: 526,638
Gas consumption (pact >= 4.8):
- 1 input/1 output: 5,540
- 1 input/10 outputs: 53,323
- 10 inputs/1 output: 55,175
- 10 inputs/10 outputs: 104,958
Equivalence:
Library | Function |
---|---|
Circomlib | MiMCSponge(nInputs, 220, nOutputs) |
CircomlibJS | MIMCSponge.multiHash() |
ZoKrates Stdlib | mimcSponge<nInputs, nOutputs>(field[nInputs] ins, field k) -> field[nOutputs] |
Pact implementation of the Poseidon hash for Kadena:
https://www.poseidon-hash.info/
https://github.com/iden3/circomlib/blob/master/circuits/poseidon.circom
https://github.com/iden3/circomlibjs/blob/main/src/poseidon_reference.js
Constants are taken from the circomlib project.
(defun poseidon-hash:integer (in:[integer])
inputs
: input list of integers
Returns the hash result as an integer.
Gas consumption (pact <= 4.7.x):
- 1 input/1 output: 19,928
- 2 inputs/1 output: 35,091
- 3 inputs/1 output: 55,473
- 4 inputs/1 output: 87,146
- 5 inputs/1 output: 121,596
Gas consumption (pact >= 4.8):
- 1 input/1 output: 5,048
- 2 inputs/1 output: 7,828
- 3 inputs/1 output: 11,142
- 4 inputs/1 output: 16,273
- 5 inputs/1 output: 21,544
Equivalence:
Library | Function |
---|---|
Circomlib | Poseidon(nInputs) |
CircomlibJS | buildPoseidon()(inputs, 0 1) |
ZoKrates Stdlib | poseidon(field[N] inputs) -> field |