Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Commit

Permalink
update op hash
Browse files Browse the repository at this point in the history
  • Loading branch information
brech1 committed Oct 26, 2023
1 parent c85a393 commit 847e364
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
20 changes: 20 additions & 0 deletions eigentrust-zk/src/circuits/dynamic_sets/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,26 @@ impl<
op_hash
}

/// Build the opinion group by unwrapping attestations and filling the empty ones with default values.
/// Enumerating to keep track of the participant this opinion is about.
pub fn parse_op_group(
&mut self, op: Vec<Option<SignedAttestation<C, N, NUM_LIMBS, NUM_BITS, P>>>,
) -> Vec<SignedAttestation<C, N, NUM_LIMBS, NUM_BITS, P>> {
// Get participant set addresses
let set: Vec<N> = self.set.iter().map(|&(addr, _)| addr).collect();

op.into_iter()
.enumerate()
.map(|(index, attestation)| {
attestation.unwrap_or_else(|| {
SignedAttestation::<C, N, NUM_LIMBS, NUM_BITS, P>::empty_with_about(
set[index], self.domain,
)
})
})
.collect()
}

/// Method for filtering invalid opinions
fn filter_peers_ops(&self) -> HashMap<N, Vec<N>> {
let mut filtered_ops: HashMap<N, Vec<N>> = HashMap::new();
Expand Down
24 changes: 15 additions & 9 deletions eigentrust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ use circuit::{Circuit, ETReport, ETSetup, ThPublicInputs, ThReport, ThSetup};
use eigentrust_zk::{
circuits::{
threshold::native::Threshold, ECDSAPublicKey, EigenTrust4, KZGParams, NativeAggregator4,
NativeEigenTrust4, NativeThreshold4, PoseidonNativeSponge, Threshold4, HASHER_WIDTH,
MIN_PEER_COUNT, NUM_DECIMAL_LIMBS, NUM_NEIGHBOURS, POWER_OF_TEN,
NativeEigenTrust4, NativeThreshold4, Opinion4, PoseidonNativeSponge, Threshold4,
HASHER_WIDTH, MIN_PEER_COUNT, NUM_DECIMAL_LIMBS, NUM_NEIGHBOURS, POWER_OF_TEN,
},
halo2::{
arithmetic::Field,
Expand Down Expand Up @@ -418,15 +418,26 @@ impl Client {
native_et.add_member(scalar_set[i]);
}

// Submit participants' opinion to native set and get opinion hashes
// Submit participants' opinion
let mut op_hashes: Vec<Scalar> = Vec::new();
for (origin_index, member) in address_set.clone().into_iter().enumerate() {
if let Some(pub_key) = pub_key_map.get(&member) {
debug!("Updating opinion for {}", member);
let opinion = attestation_matrix[origin_index].clone();
op_hashes.push(native_et.update_op(pub_key.clone(), opinion));
native_et.update_op(pub_key.clone(), opinion.clone());

// Get opinion hash
let parsed_op = native_et.parse_op_group(opinion);
let op = Opinion4::new(pub_key.clone(), parsed_op, scalar_domain);
let (_, _, op_hash) = op.validate(scalar_set.clone());
op_hashes.push(op_hash)
}
}

let mut sponge = PoseidonNativeSponge::new();
sponge.update(&op_hashes);
let opinions_hash = sponge.squeeze();

// Calculate scores
let rational_scores = native_et.converge_rational();
let scalar_scores: Vec<Scalar> = native_et.converge();
Expand All @@ -443,11 +454,6 @@ impl Client {
"There are more participants than scores"
);

// Generate opinions' sponge hash.
let mut sponge = PoseidonNativeSponge::new();
sponge.update(&op_hashes);
let opinions_hash = sponge.squeeze();

// Build public inputs
let pub_inputs =
ETPublicInputs::new(scalar_set, scalar_scores, scalar_domain, opinions_hash);
Expand Down

0 comments on commit 847e364

Please sign in to comment.