You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the example above, a binary tree of height 22 is being built. Each leaf is considered to be a 136 byte long array. The leaves and digests are aligned in a flat array. You can also use keccak512 in `build_keccak512_merkle_tree` function.
The `PoseidonConfig::default()` can be modified, by default the inputs and outputs are set to be on `Host` for example.
122
+
The `HashConfig` can be modified, by default the inputs and outputs are set to be on `Host` for example.
124
123
125
124
```rust
126
-
impl<'a> DefaultforPoseidonConfig<'a> {
125
+
impl<'a> DefaultforHashConfig<'a> {
127
126
fndefault() ->Self {
128
127
letctx=get_default_device_context();
129
128
Self {
130
129
ctx,
131
130
are_inputs_on_device:false,
132
131
are_outputs_on_device:false,
133
-
input_is_a_state:false,
134
-
aligned:false,
135
-
loop_state:false,
136
132
is_async:false,
137
133
}
138
134
}
139
135
}
140
136
```
141
137
142
-
In the example above `load_optimized_poseidon_constants::<F>(arity, &ctx).unwrap();` is used which will load the correct constants based on arity and curve. Its possible to [generate](#constants) your own constants and load them.
138
+
In the example above `Poseidon::load(arity, &ctx).unwrap();` is used which will load the correct constants based on arity and curve. Its possible to [generate](#constants) your own constants and load them.
arity, // The arity of poseidon hash. The width will be equal to arity + 1
144
+
alpha, // The S-box power
145
+
full_rounds_half,
146
+
partial_rounds,
147
+
round_constants,
148
+
mds_matrix,
149
+
non_sparse_matrix,
150
+
sparse_matrices,
151
+
domain_tag,
152
+
ctx,
153
+
)
154
+
.unwrap();
169
155
```
170
156
171
157
## The Tree Builder
@@ -175,21 +161,34 @@ The tree builder allows you to build Merkle trees using Poseidon.
175
161
You can define both the tree's `height` and its `arity`. The tree `height` determines the number of layers in the tree, including the root and the leaf layer. The `arity` determines how many children each internal node can have.
[Poseidon2](https://eprint.iacr.org/2023/323) is a recently released optimized version of Poseidon1. The two versions differ in two crucial points. First, Poseidon is a sponge hash function, while Poseidon2 can be either a sponge or a compression function depending on the use case. Secondly, Poseidon2 is instantiated by new and more efficient linear layers with respect to Poseidon. These changes decrease the number of multiplications in the linear layer by up to 90% and the number of constraints in Plonk circuits by up to 70%. This makes Poseidon2 currently the fastest arithmetization-oriented hash function without lookups.
4
+
5
+
6
+
## Using Poseidon2
7
+
8
+
ICICLE Poseidon2 is implemented for GPU and parallelization is performed for each state.
9
+
We calculate multiple hash-sums over multiple pre-images in parallel, rather than going block by block over the input vector.
10
+
11
+
For example, for Poseidon2 of width 16, input rate 8, output elements 8 and input of size 1024 * 8, we would expect 1024 * 8 elements of output. Which means each input block would be of size 8, resulting in 1024 Poseidon2 hashes being performed.
Poseidon2 is also extremely customizable and using different constants will produce different hashes, security levels and performance results.
20
+
21
+
We support pre-calculated constants for each of the [supported curves](../core#supported-curves-and-operations). The constants can be found [here](https://github.com/ingonyama-zk/icicle/tree/main/icicle/include/poseidon2/constants) and are labeled clearly per curve `<curve_name>_poseidon2.h`.
22
+
23
+
You can also use your own set of constants as shown [here](https://github.com/ingonyama-zk/icicle/blob/main/wrappers/rust/icicle-fields/icicle-babybear/src/poseidon2/mod.rs#L290)
24
+
25
+
### Rust API
26
+
27
+
This is the most basic way to use the Poseidon2 API.
In the example above `Poseidon2::load(width, rate, MdsType::Default, DiffusionStrategy::Default, &ctx).unwrap();` is used to load the correct constants based on width and curve. Here, the default MDS matrices and diffusion are used. If you want to get a Plonky3 compliant version, set them to `MdsType::Plonky` and `DiffusionStrategy::Montgomery` respectively.
54
+
55
+
## The Tree Builder
56
+
57
+
Similar to Poseidon1, you can use Poseidon2 in a tree builder.
0 commit comments