forked from Dshield-xyz/Dshield
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhasher.json
More file actions
1 lines (1 loc) · 4.17 KB
/
Copy pathhasher.json
File metadata and controls
1 lines (1 loc) · 4.17 KB
1
{"noir_version":"1.0.0-beta.9+6abff2f16e1c1314ba30708d1cf032a536de3d19","hash":"7135887383329252322","abi":{"parameters":[{"name":"a","type":{"kind":"field"},"visibility":"private"},{"name":"b","type":{"kind":"field"},"visibility":"private"}],"return_type":{"abi_type":{"kind":"field"},"visibility":"public"},"error_types":{}},"bytecode":"H4sIAAAAAAAA/7WSUQrDIBBE1Zi23z3Jrqtx/etVKjX3P0GpJQaWSH+a5MGwg6CMo1ot3Kqs6tFtPtokmLwv0RUkfIJLmQP4kCdGxsDh5ZiosOeYcoqQ0FPBOSSaYWEQZ8FOzsxp/8/ptgvfbHfR75r13bwWfhDeNr/uG6suVdcf72U2HcA+0BzY53hcLtDi7kb1f0B6o3o+BOgFCPQCAAA=","debug_symbols":"nZPLroMgEIbfZdYuuCiKr3JyYlCxISFoKDRpjO9eNKJ1QRduuA3fzz8wzNDL1j8aZYbxCfXfDK1VWqtHo8dOODWasDovGcRp46yUYQm+4oGahJXGQW281hm8hPbbpuckzNY7YUMUZSBNH/ogOCgt19GSnTRKo5zuLMb8oIsrjtM4LcjOU16efHXhSZonBEcDhBCWUqBpBYzzMwXGbnko0eGhylMKxQ8PZZFHD2VJUwrsxzMQtgtwym/wGKHjFlDO7uRQ8XgLmKNrDv9hJjplL8ULCOoqA7y1JLTLKm6VaLXci3vwpvuqdfeeYiT+hsmOney9lav0FguHfQA=","file_map":{"50":{"source":"use dep::poseidon::poseidon2::Poseidon2;\n\npub fn main(a: Field, b: Field) -> pub Field {\n Poseidon2::hash([a, b], 2)\n}\n","path":"/home/caxton/work/Dshield/circuits/hasher/src/main.nr"},"58":{"source":"use std::default::Default;\nuse std::hash::Hasher;\n\ncomptime global RATE: u32 = 3;\n\npub struct Poseidon2 {\n cache: [Field; 3],\n state: [Field; 4],\n cache_size: u32,\n squeeze_mode: bool, // 0 => absorb, 1 => squeeze\n}\n\nimpl Poseidon2 {\n #[no_predicates]\n pub fn hash<let N: u32>(input: [Field; N], message_size: u32) -> Field {\n Poseidon2::hash_internal(input, message_size)\n }\n\n pub(crate) fn new(iv: Field) -> Poseidon2 {\n let mut result =\n Poseidon2 { cache: [0; 3], state: [0; 4], cache_size: 0, squeeze_mode: false };\n result.state[RATE] = iv;\n result\n }\n\n fn perform_duplex(&mut self) {\n // add the cache into sponge state\n for i in 0..RATE {\n // We effectively zero-pad the cache by only adding to the state\n // cache that is less than the specified `cache_size`\n if i < self.cache_size {\n self.state[i] += self.cache[i];\n }\n }\n self.state = crate::poseidon2_permutation(self.state, 4);\n }\n\n fn absorb(&mut self, input: Field) {\n assert(!self.squeeze_mode);\n if self.cache_size == RATE {\n // If we're absorbing, and the cache is full, apply the sponge permutation to compress the cache\n self.perform_duplex();\n self.cache[0] = input;\n self.cache_size = 1;\n } else {\n // If we're absorbing, and the cache is not full, add the input into the cache\n self.cache[self.cache_size] = input;\n self.cache_size += 1;\n }\n }\n\n fn squeeze(&mut self) -> Field {\n assert(!self.squeeze_mode);\n // If we're in absorb mode, apply sponge permutation to compress the cache.\n self.perform_duplex();\n self.squeeze_mode = true;\n\n // Pop one item off the top of the permutation and return it.\n self.state[0]\n }\n\n fn hash_internal<let N: u32>(input: [Field; N], in_len: u32) -> Field {\n let two_pow_64 = 18446744073709551616;\n let iv: Field = (in_len as Field) * two_pow_64;\n let mut sponge = Poseidon2::new(iv);\n for i in 0..input.len() {\n if i < in_len {\n sponge.absorb(input[i]);\n }\n }\n sponge.squeeze()\n }\n}\n\npub struct Poseidon2Hasher {\n _state: [Field],\n}\n\nimpl Hasher for Poseidon2Hasher {\n fn finish(self) -> Field {\n let iv: Field = (self._state.len() as Field) * 18446744073709551616; // iv = (self._state.len() << 64)\n let mut sponge = Poseidon2::new(iv);\n for i in 0..self._state.len() {\n sponge.absorb(self._state[i]);\n }\n sponge.squeeze()\n }\n\n fn write(&mut self, input: Field) {\n self._state = self._state.push_back(input);\n }\n}\n\nimpl Default for Poseidon2Hasher {\n fn default() -> Self {\n Poseidon2Hasher { _state: &[] }\n }\n}\n","path":"/home/caxton/nargo/github.com/noir-lang/poseidon/v0.2.0/src/poseidon2.nr"}},"names":["main"],"brillig_names":[]}