Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions simulations/benchmark_voting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import timeit
import random
import math
from simulations.engine import Engine, Proposal

def setup_benchmark(num_honest=500, num_malicious=100, num_proposals=50):
Expand Down
2 changes: 1 addition & 1 deletion simulations/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def run_epoch(self): # noqa: C901
target_malicious = []
other_malicious = []
for p in active_proposals:
if math.isclose(p.target_rho, malicious_target_rho, abs_tol=1e-9):
if p.target_rho == malicious_target_rho:
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.

high

Comparing floating-point numbers using the equality operator (==) is unreliable due to precision issues inherent in binary representation. While the current simulation values might happen to align, this approach is fragile and can lead to incorrect logic if the calculation of target_rho or the constants change. It is safer and more robust to use math.isclose() with an appropriate tolerance, as was previously implemented. Additionally, this change introduces an inconsistency with the benchmark script and the honest agent categorization logic, both of which still utilize tolerance-based comparisons.

Suggested change
if p.target_rho == malicious_target_rho:
if math.isclose(p.target_rho, malicious_target_rho, abs_tol=1e-9):

target_malicious.append(p)
else:
other_malicious.append(p)
Expand Down
Loading