Skip to content

Commit

Permalink
POC implementation for mutliproof proposal in cfrg#177
Browse files Browse the repository at this point in the history
* Support multiproofs in Prio3
* Add new Prio3SumVec variant, i.e. Prio3SumVecWithMultiproof, with configuration (field size, number of proofs)
* Add with_field class methods to introduce new SumVec with configurable field size
  • Loading branch information
albertpl committed Oct 14, 2023
1 parent 402438c commit e11c788
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 59 deletions.
33 changes: 26 additions & 7 deletions poc/flp_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ def check_valid_eval(self, meas, joint_rand):
if len(joint_rand) != self.JOINT_RAND_LEN:
raise ERR_INPUT

@classmethod
def with_field(cls, field: field.FftField):
class _ValidWithField(cls):
Field = field
return _ValidWithField


class ProveGadget:
def __init__(self, Field, wire_seeds, g, g_calls):
Expand Down Expand Up @@ -829,6 +835,22 @@ def decode(self, output, num_measurements):
return total // num_measurements


# Test encoding, truncation, then decoding.
def test_encode_truncate_decode(flp, measurements):
for measurement in measurements:
assert measurement == flp.decode(
flp.truncate(flp.encode(measurement)), 1)


def test_encode_truncate_decode_with_fft_fields(cls, measurements, *args):
for f in [field.Field64, field.Field96, field.Field128]:
cls_with_field = cls.with_field(f)
assert cls_with_field.Field == f
obj = cls_with_field(*args)
assert isinstance(obj, cls)
test_encode_truncate_decode(FlpGeneric(obj), measurements)


def test():
flp = FlpGeneric(Count())
test_flp_generic(flp, [
Expand All @@ -848,9 +870,7 @@ def test():
(flp.encode(2 ** 10 - 1), True),
(flp.Field.rand_vec(10), False),
])
# Roundtrip test with no proof generated.
for meas in [0, 100, 2 ** 10 - 1]:
assert meas == flp.decode(flp.truncate(flp.encode(meas)), 1)
test_encode_truncate_decode(flp, [0, 100, 2 ** 10 - 1])

flp = FlpGeneric(Histogram(4, 2))
test_flp_generic(flp, [
Expand All @@ -864,10 +884,9 @@ def test():
])

# SumVec with length 2, bits 4, chunk len 1.
flp = FlpGeneric(SumVec(2, 4, 1))
# Roundtrip test with no proof generated.
for meas in [[1, 2], [3, 4], [5, 6], [7, 8]]:
assert meas == flp.decode(flp.truncate(flp.encode(meas)), 1)
test_encode_truncate_decode_with_fft_fields(SumVec,
[[1, 2], [3, 4], [5, 6], [7, 8]],
2, 4, 1)

flp = FlpGeneric(TestMultiGadget())
test_flp_generic(flp, [
Expand Down
Loading

0 comments on commit e11c788

Please sign in to comment.