From dc8590800dcbf41035f61b51135f814541526039 Mon Sep 17 00:00:00 2001 From: hewigovens <360470+hewigovens@users.noreply.github.com> Date: Fri, 18 Aug 2023 18:15:48 +0900 Subject: [PATCH] update main and evaluate_polynomial --- README.md | 4 ++-- circuits/Nargo.toml | 5 +++-- circuits/src/main.nr | 31 +++++++++++++++++++++++++++++-- tsconfig.json | 2 +- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 33c213e..72869b1 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ __Note: The [file](utils/populate.ts) being used to populate the inputs is also yarn ``` -* Make sure you are using the nargo version `0.7.1`. The libraries being used are only compatible with this version. You can check your nargo version using the below command +* Make sure you are using the nargo version matches the libraries (`ecrecover`) being used are only compatible with this version. You can check your nargo version using the below command ```bash nargo --version @@ -85,7 +85,7 @@ noirup -v 0.7.1 ``` git checkout -b solution ``` - + - Make changes to the `circuits/src/main.nr` file. - Run Tests diff --git a/circuits/Nargo.toml b/circuits/Nargo.toml index 003903b..29560e2 100644 --- a/circuits/Nargo.toml +++ b/circuits/Nargo.toml @@ -1,6 +1,7 @@ [package] +name = "stealthdrop" authors = [""] -compiler_version = "0.7.1" +compiler_version = "0.9.0" [dependencies] -ecrecover = { tag = "v0.8.0", git = "https://github.com/colinnielsen/ecrecover-noir" } +ecrecover = { tag = "v0.9.0", git = "https://github.com/colinnielsen/ecrecover-noir" } diff --git a/circuits/src/main.nr b/circuits/src/main.nr index b67efe0..6ca5c5a 100644 --- a/circuits/src/main.nr +++ b/circuits/src/main.nr @@ -11,11 +11,38 @@ fn main( polynomial_commitment: Field, nullifier: pub [u8; 32], ) { - // Write your main logic here + + let nullifier_hash = std::hash::blake2s(signature); + assert(nullifier_hash == nullifier); + std::println("checking nullifier passed"); + + let mut pub_key_x = [0; 32]; + let mut pub_key_y = [0; 32]; + for i in 0..32 { + pub_key_x[i] = pub_key[i]; + pub_key_y[i] = pub_key[i + 32]; + } + let signer = ecrecover::ecrecover(pub_key_x, pub_key_y, signature, hashed_message); + std::println("signer address recovered"); + + let polynomial_hash = std::hash::pedersen(polynomial); + assert(polynomial_hash[0] == polynomial_commitment); + std::println("checking polynomial commitment passed"); + + let value = evaluate_polynomial(polynomial, signer); + assert(value == 0); + std::println("evaluation of address passed"); } fn evaluate_polynomial(polynomial: [Field; CANDIDATES + 1], x: Field) -> Field { - // Write logic to evaluate polynomial here + let mut mult = 1; + let mut evaluation = 0; + + for i in 0..CANDIDATES + 1 { + evaluation = mult * polynomial[i] + evaluation; + mult = mult * x; + } + evaluation } #[test] diff --git a/tsconfig.json b/tsconfig.json index 76e6d8d..c2b8029 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,4 +24,4 @@ "node_modules", "**/node_modules/**" ] -} \ No newline at end of file +}