Closed vvasseur closed 3 months ago
Hello and thanks for the bug report.
I wrote a fix in #171 . Before merging it, I'd like to be sure that it also fixes the other issues you identified. Could you provide example scripts for these ?
Thanks for looking into this so quickly.
Here is a script showing the other issue I mentioned:
from scalib.attacks import FactorGraph, BPState
import numpy as np
nc = 256
g_pub = f"""
NC {nc}
PUB SINGLE s
VAR MULTI a0
VAR MULTI a1
PROPERTY s = a0 + a1
"""
g_var = f"""
NC {nc}
VAR SINGLE s
VAR MULTI a0
VAR MULTI a1
PROPERTY s = a0 + a1
"""
n = 1
fg_pub = FactorGraph(g_pub)
fg_var = FactorGraph(g_var)
bp_pub = BPState(fg_pub, n, {"s": 42})
bp_pub.set_evidence("a0", np.array([[1.0 if i == 41 else 0.0 for i in range(nc)]]))
bp_var = BPState(fg_var, n)
bp_var.set_evidence("s", np.array([1.0 if i == 42 else 0.0 for i in range(nc)]))
bp_var.set_evidence("a0", np.array([[1.0 if i == 41 else 0.0 for i in range(nc)]]))
bp_pub.bp_loopy(100, True)
bp_var.bp_loopy(100, True)
print("PUB:", np.argmax(bp_pub.get_distribution("a1")))
print("VAR:", np.argmax(bp_var.get_distribution("a1")))
This script runs on version 0.5.8 (pre-fix). With only two variables (a0
and a1
), there is no out of bounds error. But there is still an issue:
PUB: 255
VAR: 1
The VAR
version correctly identifies 1 as the most likely value for a1
(since 41 + 1 = 42), while the PUB
version incorrectly suggests 255.
Thanks! That other bug is fixed. I'll merge the PR and have a release before the end of the month.
Describe the bug An index out of bounds error occurs during belief propagation. This error is triggered when setting a constant sum constraint as a public variable in the factor graph definition.
To Reproduce
Observed behavior The script crashes with the following error:
Additional observations
PUB SINGLE
). There is no problem ifs
is defined as aVAR SINGLE
andset_evidence
is used with a distribution containing all zeros except for one 1.a0
,a1
instead of three, there is no error but the constraint does not seem to be taken into account at all.Environment: