Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example and docs for hash API #624

Merged
merged 9 commits into from
Oct 10, 2024
Merged

example and docs for hash API #624

merged 9 commits into from
Oct 10, 2024

Conversation

yshekel
Copy link
Collaborator

@yshekel yshekel commented Oct 9, 2024

This PR adds:
(1) documentation for hash apis
(2) rust example for hash api

@yshekel yshekel changed the title example for hash API example and docs for hash API Oct 9, 2024
@yshekel yshekel marked this pull request as ready for review October 9, 2024 13:16
@yshekel yshekel force-pushed the yshekel/hash_example branch 2 times, most recently from 88bafb4 to 4d2ae12 Compare October 9, 2024 15:12

ICICLE’s hashing system is designed to be flexible, efficient, and optimized for both general-purpose and cryptographic operations. Hash functions are essential in operations such as generating commitments, constructing Merkle trees, executing the Sumcheck protocol, and more.

ICICLE provides an easy-to-use interface for hashing on both CPU and GPU, with transparent backend selection. You can choose between several hash algorithms such as Keccak-256, Keccak-512, SHA3-256, SHA3-512, Blake2s, and Poseidon, which are optimized for processing both general data and cryptographic field elements or elliptic curve points.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add:
(additional hash function might be added in the future. Stay tuned)


### Blake2s

Blake2s is an optimized cryptographic hash function that provides high performance while ensuring strong security. Blake2s is ideal for hashing small data (such as field elements), especially when speed is crucial. It produces a 256-bit (32-byte) output and is often used in cryptographic protocols.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reference?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reference from the litriture for what is blake - like you did in sha

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added for blake2s and poseidon too


### Poseidon

Poseidon is a hash function designed specifically for cryptographic field elements and elliptic curve points. It is optimized for zero-knowledge proofs (ZKPs) and is often used in ZK-SNARK systems. Poseidon’s strength lies in its efficiency when working with cryptographic data, making it ideal for scenarios like Merkle tree construction and proof generation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it is ideal for merkle tree?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't know. chatgpt wrote this part. I will refine it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

auto sha3_256 = Sha3_256::create();
auto sha3_512 = Sha3_512::create();
auto blake2s = Blake2s::create();
auto poseidon = Poseidon::create<scalar_t>(arity); // Poseidon requires specifying the field type and arity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supported arity are {3,5,9,12}


The ICICLE library provides Rust bindings for hashing using a variety of cryptographic hash functions. These hash functions are optimized for both general-purpose data and cryptographic operations such as multi-scalar multiplication, commitment generation, and Merkle tree construction.

This guide will show you how to use the ICICLE hashing API in Rust with examples for common hash algorithms, such as Keccak-256, Keccak-512, SHA3-256, SHA3-512, Blake2s, and Poseidon.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a pointer to primitives::hash.md
?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

// Execute the Keccak hashing example
keccak_hash_example();

// TODO: Implement a Merkle tree example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do it in the next PR. I can write it but not sure if it would work until we merge the implementation

2. String Hashing: Demonstrates hashing of basic strings using Keccak-256.
3. Field Element Hashing: Hash Babybear field elements.
4. Batch Hashing: Hash a large batch of field elements and measure the performance.
5. (TODO merkle tree)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we have the api for that, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we do. I will update the example in another PR for merkle tree but for 3.1

Copy link
Contributor

@mickeyasa mickeyasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work

@yshekel yshekel merged commit 7a54f1d into main Oct 10, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants