-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7da2502
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: [main, master] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Install Nargo | ||
uses: noir-lang/[email protected] | ||
with: | ||
toolchain: nightly | ||
|
||
- name: Run tests | ||
run: | | ||
nargo test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "noir_toy_hashing" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = "0.9.1" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
## Noir FNV Hashing | ||
|
||
The goal of this assignment is to learn the basics of Noir by implementing FNV hashing. | ||
|
||
FNV (Fowler-Noll-Vo) hashing is a family of non-cryptographic hash functions that are designed to be fast and efficient while producing a relatively good distribution of hash values. | ||
|
||
The FNV hash algorithm operates on a byte sequence and produces a hash value. It starts with an initial value, usually a prime number, and then processes each byte of the input data, updating the hash value using a simple multiplication and XOR operation. | ||
|
||
The basic implementation of an FNV algorithm in python is given below: | ||
|
||
```python | ||
def fnv_hash(data): | ||
size = 2**32 | ||
hash_value = 0x811C9DC5 | ||
prime = 0x1000193 | ||
|
||
for byte in data: | ||
product = (hash_value * prime) % size | ||
hash_value = (product ^ byte) | ||
|
||
return hash_value | ||
``` | ||
|
||
The function when given a value of `0x079A6F9C` returns the hashed value `0x71233de7`. Your goal for this assignment is to implement this in Noir. Use the same values of size, initial value and prime number. | ||
|
||
## Evaluation | ||
|
||
- Create a fork of this repo | ||
|
||
- Clone the forked repo. You can use the following command after replacing the `CLONE_URL` with the clone url of your repo | ||
|
||
``` | ||
git clone CLONE_URL | ||
``` | ||
|
||
- Make changes to the `src/main.nr` file. Add your hashing logic to `calculate_hash` function. The function should take in a value and return its hash. | ||
|
||
- Run Tests | ||
``` | ||
nargo test | ||
``` | ||
|
||
- Push your changes to `main` branch of your forked repo. | ||
|
||
- Submit your name, email and link to your forked repo [here](https://airtable.com/apppwJwKgRGomJLLY/shrlDlkFR3XZKZRmN). | ||
|
||
## Reference | ||
|
||
- [Noir Docs](https://noir-lang.org/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
global PRIME: u32 = 16777619; | ||
|
||
fn main(value: u32, hash_value: pub u32){ | ||
let calculated_hash_value = calculate_hash(value); | ||
|
||
assert(calculated_hash_value == hash_value); | ||
} | ||
|
||
fn calculate_hash(num: u32) -> u32 { | ||
|
||
} | ||
|
||
#[test] | ||
fn test_main() { | ||
let num = 127561628; | ||
let hash = calculate_hash(num); | ||
|
||
assert(hash == 0x71233de7); | ||
main(num, hash); | ||
} |