From 7da2502937c88240b55e49352113b6914ae951f8 Mon Sep 17 00:00:00 2001 From: Shubham Kanodia Date: Tue, 15 Aug 2023 13:29:41 +0530 Subject: [PATCH] Add assignment --- .github/workflows/test.yml | 20 ++++++++++++++++ Nargo.toml | 7 ++++++ README.md | 49 ++++++++++++++++++++++++++++++++++++++ src/main.nr | 20 ++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 Nargo.toml create mode 100644 README.md create mode 100644 src/main.nr diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..fcbad9c --- /dev/null +++ b/.github/workflows/test.yml @@ -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/noirup@v0.1.2 + with: + toolchain: nightly + + - name: Run tests + run: | + nargo test diff --git a/Nargo.toml b/Nargo.toml new file mode 100644 index 0000000..28ced1b --- /dev/null +++ b/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "noir_toy_hashing" +type = "bin" +authors = [""] +compiler_version = "0.9.1" + +[dependencies] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..49e0196 --- /dev/null +++ b/README.md @@ -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/) diff --git a/src/main.nr b/src/main.nr new file mode 100644 index 0000000..318a5fb --- /dev/null +++ b/src/main.nr @@ -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); +}