Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiproof in PINE #41

Merged
merged 1 commit into from
Dec 21, 2023
Merged
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
2 changes: 1 addition & 1 deletion poc/draft-irtf-cfrg-vdaf
Submodule draft-irtf-cfrg-vdaf updated 40 files
+2 −0 .github/workflows/test.yml
+3 −0 .gitmodules
+402 −291 draft-irtf-cfrg-vdaf.md
+1 −1 poc/common.py
+6 −6 poc/daf.py
+1 −0 poc/draft-irtf-cfrg-kangarootwelve
+185 −10 poc/flp_generic.py
+8 −4 poc/idpf_poplar.py
+101 −0 poc/plot_prio3_multiproof_robustness.py
+0 −52 poc/test_vec/07/IdpfPoplar_0.json
+0 −56 poc/test_vec/07/Poplar1_0.json
+0 −64 poc/test_vec/07/Poplar1_1.json
+0 −64 poc/test_vec/07/Poplar1_2.json
+0 −76 poc/test_vec/07/Poplar1_3.json
+0 −52 poc/test_vec/07/Prio3Histogram_0.json
+0 −89 poc/test_vec/07/Prio3Histogram_1.json
+0 −194 poc/test_vec/07/Prio3SumVec_0.json
+0 −146 poc/test_vec/07/Prio3SumVec_1.json
+0 −40 poc/test_vec/07/Prio3Sum_0.json
+0 −46 poc/test_vec/07/Prio3Sum_1.json
+0 −8 poc/test_vec/07/XofFixedKeyAes128.json
+0 −8 poc/test_vec/07/XofShake128.json
+52 −0 poc/test_vec/08/IdpfPoplar_0.json
+56 −0 poc/test_vec/08/Poplar1_0.json
+64 −0 poc/test_vec/08/Poplar1_1.json
+64 −0 poc/test_vec/08/Poplar1_2.json
+76 −0 poc/test_vec/08/Poplar1_3.json
+7 −7 poc/test_vec/08/Prio3Count_0.json
+10 −10 poc/test_vec/08/Prio3Count_1.json
+52 −0 poc/test_vec/08/Prio3Histogram_0.json
+89 −0 poc/test_vec/08/Prio3Histogram_1.json
+194 −0 poc/test_vec/08/Prio3SumVec_0.json
+146 −0 poc/test_vec/08/Prio3SumVec_1.json
+40 −0 poc/test_vec/08/Prio3Sum_0.json
+46 −0 poc/test_vec/08/Prio3Sum_1.json
+8 −0 poc/test_vec/08/XofFixedKeyAes128.json
+8 −0 poc/test_vec/08/XofTurboShake128.json
+12 −12 poc/vdaf_poplar1.py
+233 −69 poc/vdaf_prio3.py
+35 −25 poc/xof.py
49 changes: 33 additions & 16 deletions poc/flp_pine.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
dir_name = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(dir_name, "draft-irtf-cfrg-vdaf", "poc"))
from common import Unsigned, front, gen_rand, next_power_of_2
from field import Field, Field128
from field import Field, Field128, Field64
from flp_generic import FlpGeneric, Mul, ParallelSum, Valid, test_flp_generic
from xof import Xof, XofShake128
from xof import Xof, XofFixedKeyAes128


class PineValid(Valid):
Expand All @@ -37,10 +37,25 @@ class PineValid(Valid):
# Number of bits in the encoded measurement.
bit_checked_len = None

# XOF for `PineValid`.
# Note we currently use `XofFixedKeyAes128` by default, because
# `XofTurboShake128` in VDAF poc has a limit of how many bytes can be
# sampled:
# https://github.com/cfrg/draft-irtf-cfrg-vdaf/blob/fd7a2dc4993babbf3acffc7d498cd7925890064b/poc/xof.py#L18-L21.
# TODO(junyechen1996): Switch to TurboShake128 after
# https://github.com/cfrg/draft-irtf-cfrg-vdaf/pull/322 is merged.
Xof = XofFixedKeyAes128

# Associated types for `Valid`.
Measurement = list[float]
AggResult = list[float]
Field = Field128
Field = None # Set by `with_field()`.

@classmethod
def with_field(PineValid, TheField):
class PineValidWithField(PineValid):
Field = TheField
return PineValidWithField

def __init__(self,
l2_norm_bound: float,
Expand Down Expand Up @@ -513,30 +528,32 @@ def test_bit_chunks():
assert bits_str == bit_chunks_str

def test_pine_valid_roundtrip():
valid = PineValid(1.0, 15, 2, 1)
valid = PineValid.with_field(Field128)(1.0, 15, 2, 1)
f64_vals = [0.5, 0.5]
assert f64_vals == valid.decode(valid.truncate(valid.encode(f64_vals)), 1)

def test():
test_bit_chunks()
test_pine_valid_roundtrip()

# `PineValid` with `l2_norm_bound = 1.0`, `num_frac_bits = 4`,
# `dimension = 4`, `chunk_length = 150`.
l2_norm_bound = 1.0
# 4 fractional bits should be enough to keep 1 decimal digit.
num_frac_bits = 4
dimension = 4
args = [l2_norm_bound, 4, dimension, 150]
# A gradient with a L2-norm of exactly 1.0.
measurement = [l2_norm_bound / 2] * dimension
pine_valid = PineValid(l2_norm_bound, num_frac_bits, dimension, 150)
flp = FlpGeneric(pine_valid)

# Test PINE FLP with verification.
xof = XofShake128(gen_rand(16), b"", b"")
encoded_gradient = flp.encode(measurement)
(wr_check_bits, wr_dot_prods) = \
pine_valid.run_wr_checks(encoded_gradient, xof)
flp_meas = encoded_gradient + wr_check_bits + wr_dot_prods
test_flp_generic(flp, [(flp_meas, True)])
for field in [Field64, Field128]:
pine_valid = PineValid.with_field(field)(*args)
flp = FlpGeneric(pine_valid)

# Test PINE FLP with verification.
xof = XofFixedKeyAes128(gen_rand(16), b"", b"")
encoded_gradient = flp.encode(measurement)
(wr_check_bits, wr_dot_prods) = \
pine_valid.run_wr_checks(encoded_gradient, xof)
meas = encoded_gradient + wr_check_bits + wr_dot_prods
test_flp_generic(flp, [(meas, True)])


if __name__ == '__main__':
Expand Down
Loading