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

Add new hashing functions (SHA & Keccak) #999

Merged
merged 111 commits into from
Dec 14, 2023
Merged

Add new hashing functions (SHA & Keccak) #999

merged 111 commits into from
Dec 14, 2023

Conversation

MartinMinkov
Copy link
Contributor

@MartinMinkov MartinMinkov commented Jun 21, 2023

Description

Implements o1-labs/rfcs#9

This PR adds support for hashing using various SHA algorithms and Keccak. The OCaml bindings expose the base functionality, which calls into Kimchi.

To see example usage, see the following tests:
Unit tests: https://github.com/o1-labs/snarkyjs/pull/999/files#diff-772a0ee5ba611c22e73c36051c7139a50869713a53c357d2f6abb49abfbfa497

Integration test: https://github.com/o1-labs/snarkyjs/pull/999/files#diff-1f506bf5891efbbfba747df80700012d212be51e402f9f406e21155992858664

Note: Hashing only works for Field variables. No hashing is implemented for constant fields, which can lead to errors if users try to hash outside of a provable method. We can add a lightweight JS dependency that implements SHA/Keccak hashing and convert our constant Field values into something the JS dependency expects.

Currently waiting on 🔗 MinaProtocol/mina#12524 to be merged for proving to be enabled.

🔗 Bindings o1-labs/o1js-bindings#53

@MartinMinkov MartinMinkov linked an issue Jun 21, 2023 that may be closed by this pull request
src/lib/hash.ts Outdated Show resolved Hide resolved
src/lib/hash.ts Outdated Show resolved Hide resolved
src/lib/hash.ts Outdated Show resolved Hide resolved
@MartinMinkov MartinMinkov linked an issue Jun 26, 2023 that may be closed by this pull request
@mitschabaude
Copy link
Collaborator

new bindings: o1-labs/o1js-bindings#220

@mitschabaude
Copy link
Collaborator

Another idea for Hash.hash is that it takes any provables as input and hashes them with fewer constraints -- i.e., use the "chunked" method to convert to fields instead ot toFields

Base automatically changed from feature/keccak-and-ecdsa to main December 13, 2023 19:34
src/examples/crypto/ecdsa/ecdsa.ts Show resolved Hide resolved
src/lib/hashes-combined.ts Outdated Show resolved Hide resolved
@@ -2150,4 +2137,897 @@ describe('int', () => {
});
});
});

Copy link
Member

Choose a reason for hiding this comment

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

one day i will refactor this file to save us 3k of lines :D

src/lib/keccak-old.unit-test.ts Outdated Show resolved Hide resolved
@@ -525,6 +525,7 @@ declare const Snarky: {
};
};

// TODO: implement in TS
Copy link
Member

Choose a reason for hiding this comment

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

this would be fun 👀

@mitschabaude mitschabaude merged commit 004112d into main Dec 14, 2023
13 checks passed
@mitschabaude mitschabaude deleted the feat/add-sha branch December 14, 2023 12:53
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.

Expose SHA-3 Expose Keccak
3 participants