Skip to content

Commit

Permalink
nix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas089 committed May 25, 2024
1 parent 8bbb678 commit 7c90bca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
5 changes: 4 additions & 1 deletion api/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ impl AppState {
self.state
.elections
.iter_mut()
.filter(|election| election.gov_key == outputs.deserialized_government_public_key() && election.options.contains(&outputs.choice))
.filter(|election| {
election.gov_key == outputs.deserialized_government_public_key()
&& election.options.contains(&outputs.choice)
})
.for_each(|election| {
election
.receipts
Expand Down
45 changes: 21 additions & 24 deletions audit-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use std::collections::HashSet;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use k256::Secp256k1;
use risc0_zkvm::Receipt;
use std::fs::File;
use hex;
use bincode;
use hex;
use k256::ecdsa::Signature;
use methods::ACROPOLIS_ID;
use risc0_types::CircuitOutputs;
use k256::ecdsa::Signature;
use risc0_zkvm::Receipt;
use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;

pub fn parse_receipts_file(path: PathBuf) -> Vec<Receipt> {
let file = File::open(path).expect("Failed to read receipts file");
Expand All @@ -35,51 +33,50 @@ pub fn serialize_receipt(receipt: Receipt) -> Vec<u8> {
bincode::serialize(&receipt).expect("Failed to serialize receipt")
}

pub fn verify_receipt_vec(receipts: Vec<Receipt>, gov_pub_key: String) -> HashMap<String, u64>{
pub fn verify_receipt_vec(receipts: Vec<Receipt>, gov_pub_key: String) -> HashMap<String, u64> {
let mut identities: Vec<Signature> = Vec::new();
let mut malicious_identities: Vec<Signature> = Vec::new();
let mut valid_votes: Vec<CircuitOutputs> = Vec::new();
for receipt in receipts{
for receipt in receipts {
let journal: CircuitOutputs = receipt.journal.decode().expect("Failed to decode journal");
let journal_gov_pub: String = hex::encode(&journal.government_public_key);
let voter_identity: Signature = journal.public_identity;
if journal_gov_pub != gov_pub_key{
if journal_gov_pub != gov_pub_key {
continue;
};
if identities.contains(&voter_identity){
if !malicious_identities.contains(&voter_identity){
if identities.contains(&voter_identity) {
if !malicious_identities.contains(&voter_identity) {
malicious_identities.push(voter_identity);
};
};
if !identities.contains(&voter_identity){
if !identities.contains(&voter_identity) {
identities.push(voter_identity);
}
// verify the risc0 Receipt
match receipt.verify(ACROPOLIS_ID){
match receipt.verify(ACROPOLIS_ID) {
Ok(_) => {
if !malicious_identities.contains(&voter_identity){
if !malicious_identities.contains(&voter_identity) {
valid_votes.push(journal.clone());
}
},
}
Err(_) => {
eprintln!("Invalid proof: {:?}", &journal)
}
}
};
}
// count votes and return results
let mut votes: HashMap<String, u64> = HashMap::new();
for vote in valid_votes{
if !votes.contains_key(&vote.choice){
for vote in valid_votes {
if !votes.contains_key(&vote.choice) {
votes.insert(vote.choice.clone(), 1u64);
}
else{
} else {
let mut current_votes = *votes.get(&vote.choice).expect("Option does not exist");
current_votes += 1;
votes.insert(vote.choice, current_votes);
}
}
for result in &votes{
for result in &votes {
println!("Candidate {:?} has received {:?} votes", result.0, result.1)
}
votes
}
}
5 changes: 1 addition & 4 deletions methods/guest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ fn main() {
payload.append(circuit_inputs.government_public_key.clone().as_mut());

government_public_key
.verify(
&payload,
&circuit_inputs.public_identity,
)
.verify(&payload, &circuit_inputs.public_identity)
.expect("Failed to verify public identity");

let output: CircuitOutputs = CircuitOutputs {
Expand Down

0 comments on commit 7c90bca

Please sign in to comment.