Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions circuits/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
global CANDIDATES: Field = 2;

use dep::std;
use dep::ecrecover;

global CANDIDATES: Field = 2;

fn main(
pub_key: [u8; 64],
signature: [u8; 64],
Expand All @@ -11,11 +11,36 @@ fn main(
polynomial_commitment: Field,
nullifier: pub [u8; 32],
) {
// Write your main logic here
let mut pub_key_x: [u8; 32] = [0; 32];
let mut pub_key_y: [u8; 32] = [0; 32];

for i in 0..32 {
pub_key_x[i] = pub_key[i];
pub_key_y[i] = pub_key[i+32];
}

let address: Field = ecrecover::ecrecover(pub_key_x, pub_key_y, signature, hashed_message);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can also use from_unified for key conversion like this:

let key = ecrecover::secp256k1::PubKey::from_unified(pub_key);
let address = ecrecover::ecrecover(key.pub_x, key.pub_y, signature, hashed_message);


let evaluation = evaluate_polynomial(polynomial, address);
assert(evaluation == 0);

let check_polynomial = std::hash::pedersen(polynomial)[0];
assert(polynomial_commitment == check_polynomial);

let check_signature = std::hash::blake2s(signature);
assert(nullifier == check_signature);
}

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]
Expand Down