Skip to content

Commit

Permalink
🐛 Fix: remove the judgment bug when some players are dead.
Browse files Browse the repository at this point in the history
  • Loading branch information
sheagrief committed Nov 8, 2024
1 parent a413955 commit 35e02c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
34 changes: 23 additions & 11 deletions examples/werewolf_cli/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,24 +256,30 @@ impl Game {
fn prove_and_verify_victory(&self) {
// setup

let player_num = self.state.players.len();
let num_alive = Fr::from(self.state.players.iter().filter(|p| p.is_alive).count() as i32);

let alive_indices = self
.state
.players
.iter()
.enumerate()
.filter(|(_, p)| p.is_alive)
.map(|(i, _)| i)
.collect::<Vec<usize>>();

let rng = &mut test_rng();

let am_werewolf_vec = (0..player_num)
let am_werewolf_vec = alive_indices
.iter()
.map(|_| InputWithCommit::default())
.collect::<Vec<_>>();

let am_werewolf_val = (0..player_num)
.map(|i| self.state.players[i].is_werewolf())
.collect::<Vec<_>>();

let mpc_am_werewolf_vec = (0..player_num)
.map(|i| {
let mpc_am_werewolf_vec = alive_indices
.iter()
.map(|&i| {
let mut a: InputWithCommit<MFr> = InputWithCommit::default();
a.allocation = i;
a.input = MFr::from(am_werewolf_val[i]);
a.input = MFr::from(self.state.players[i].is_werewolf());
a
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -304,8 +310,14 @@ impl Game {

let game_state = exists_werewolf.field() * MFr::from(2_u32)
+ (!exists_werewolf).field()
* (num_werewolf.is_smaller_than(&num_citizen).field() * MFr::from(3_u32)
+ (MFr::one() - (num_werewolf.is_smaller_than(&num_citizen)).field())
* ((num_werewolf + MFr::one())
.is_smaller_than(&num_citizen)
.field()
* MFr::from(3_u32)
+ (MFr::one()
- ((num_werewolf + MFr::one())
.is_smaller_than(&num_citizen)
.field()))
* MFr::from(1_u32));

// prove
Expand Down
1 change: 1 addition & 0 deletions mpc-algebra/src/wire/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ impl<F: PrimeField + SquareRootField, S: FieldShare<F>> LessThan for MpcField<F,
!lsb_x
}

// TODO: Fix: This function should be returns false when the two values are equal.
fn is_smaller_than(&self, other: &Self) -> Self::Output {
let timer = start_timer!(|| "LessThan");
// [z]=[other−self<p/2],[x]=[self<p/2],[y]=[other>p/2]
Expand Down

0 comments on commit 35e02c4

Please sign in to comment.