Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into hadar/vecops
Browse files Browse the repository at this point in the history
  • Loading branch information
yshekel committed Nov 4, 2024
2 parents c9788e9 + a915a9e commit 0562f85
Show file tree
Hide file tree
Showing 9 changed files with 366 additions and 137 deletions.
9 changes: 8 additions & 1 deletion docs/docs/icicle/primitives/hash.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Keccak can take input messages of any length and produce a fixed-size hash. It u

Traditional hash functions, such as SHA-2, are difficult to represent within ZK circuits because they involve complex bitwise operations that don’t translate efficiently into arithmetic operations. Poseidon, however, is specifically designed to minimize the number of constraints required in these circuits, making it significantly more efficient for use in ZK-SNARKs and other cryptographic protocols that require hashing over field elements.

Currently the Poseidon implementation is the Optimized Poseidon (https://hackmd.io/@jake/poseidon-spec#Optimized-Poseidon). Optimized Poseidon significantly decreases the calculation time of the hash.

The optional `domain_tag` pointer parameter enables domain separation, allowing isolation of hash outputs across different contexts or applications.

## Using Hash API

Expand Down Expand Up @@ -94,7 +97,7 @@ eIcicleError hash(const std::byte* input, uint64_t size, const HashConfig& confi
* @tparam PREIMAGE The type of the input data.
* @tparam IMAGE The type of the output data.
* @param input Pointer to the input data.
* @param size The number of elements of type `PREIMAGE` to hash.
* @param size The number of elements of type `PREIMAGE` to a single hasher.
* @param config Configuration options for the hash operation.
* @param output Pointer to the output data.
* @return An error code of type eIcicleError indicating success or failure.
Expand Down Expand Up @@ -131,6 +134,10 @@ auto output = std::make_unique<std::byte[]>(32 * config.batch); // Allocate outp
eIcicleErr err = keccak256.hash(input.data(), input.size() / config.batch, config, output.get());
```

### 4. Posidon sponge function

Currently the poseidon sponge function (Sec 2.1 of https://eprint.iacr.org/2019/458.pdf ) isn't implemented.

### Supported Bindings

- [Rust](../rust-bindings/hash)
Expand Down
3 changes: 0 additions & 3 deletions examples/rust/hash-and-merkle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,5 @@ fn main() {
keccak_hash_example();

// Execute the Merkle-tree example
// TODO remove this when merkle-tree works on CUDA backend
println!("\nWARNING: merkle-tree example falling back to CPU");
icicle_runtime::set_device(&icicle_runtime::Device::new("CPU", 0)).unwrap();
merkle_tree_example();
}
3 changes: 2 additions & 1 deletion icicle/include/icicle/hash/poseidon.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace icicle {
*
* This function generates a Poseidon hash with customizable parameters to suit various cryptographic
* contexts and use cases. The width parameter (`t`) determines the number of elements in the state,
* influencing the security level and output structure of the hash. The optional `domain_tag` parameter
* influencing the security level and output structure of the hash. The optional `domain_tag` pointer parameter
* enables domain separation, allowing isolation of hash outputs across different contexts or applications.
* (See here for a detailed explanation: https://hackmd.io/@7dpNYqjKQGeYC7wMlPxHtQ/ByIbpfX9c#SAFE-Sponge-API-for-Field-Elements-–-A-Toolbox-for-ZK-Hash-Applications)
*
* @param S Represents the type of the field element used by the hash (e.g., a field element class).
*
Expand Down
6 changes: 3 additions & 3 deletions icicle/include/icicle/merkle/merkle_tree_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ namespace icicle {
nullptr; /**< Stream for asynchronous execution. Default is nullptr for synchronous execution. */
bool is_leaves_on_device =
false; /**< True if leaves are on the device (GPU), false if on the host (CPU). Default is false. */
bool is_tree_on_device = false; /**< True if the tree results are allocated on the device (GPU), false if on the
host (CPU). Default is false. */
bool is_async = false; /**< True for asynchronous execution, false for synchronous. Default is false. */
bool is_tree_on_device = true; /**< True if the tree results are allocated on the device (e.g. GPU), false if on
the host (CPU). Default is true. */
bool is_async = false; /**< True for asynchronous execution, false for synchronous. Default is false. */
PaddingPolicy padding_policy =
PaddingPolicy::None; /**< Policy for handling cases where the input is smaller than expected. */
ConfigExtension* ext = nullptr; /**< Backend-specific extensions for advanced configurations. Default is nullptr. */
Expand Down
Loading

0 comments on commit 0562f85

Please sign in to comment.