Skip to content

Commit

Permalink
SQUASH "vit vec" -> "bit vec"
Browse files Browse the repository at this point in the history
  • Loading branch information
cjpatton committed Oct 15, 2024
1 parent 28c7f4e commit b0decf1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
22 changes: 11 additions & 11 deletions draft-irtf-cfrg-vdaf.md
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,7 @@ are used to encode measurements in some variants of Prio3
({{prio3-instantiations}}).

~~~ python
def encode_into_vit_vec(
def encode_into_bit_vec(
cls,
val: int,
bits: int) -> list[Self]:
Expand All @@ -2002,7 +2002,7 @@ def encode_into_vit_vec(
encoded.append(cls((val >> l) & 1))
return encoded

def decode_from_vit_vec(cls, vec: list[Self]) -> Self:
def decode_from_bit_vec(cls, vec: list[Self]) -> Self:
"""
Decode the field element from the bit representation, expressed
as a vector of field elements `vec`.
Expand Down Expand Up @@ -3865,25 +3865,25 @@ class Sum(Valid[int, int, F]):
out.append(self.GADGETS[0].eval(self.field, [b]))

range_check = self.offset * shares_inv + \
self.field.decode_from_vit_vec(meas[:self.bits]) - \
self.field.decode_from_vit_vec(meas[self.bits:])
self.field.decode_from_bit_vec(meas[:self.bits]) - \
self.field.decode_from_bit_vec(meas[self.bits:])
out.append(range_check)
return out

def encode(self, measurement: int) -> list[F]:
encoded = []
encoded += self.field.encode_into_vit_vec(
encoded += self.field.encode_into_bit_vec(
measurement,
self.bits
)
encoded += self.field.encode_into_vit_vec(
encoded += self.field.encode_into_bit_vec(
measurement + self.offset.int(),
self.bits
)
return encoded

def truncate(self, meas: list[F]) -> list[F]:
return [self.field.decode_from_vit_vec(meas[:self.bits])]
return [self.field.decode_from_bit_vec(meas[:self.bits])]

def decode(self, output: list[F], _num_measurements: int) -> int:
return output[0].int()
Expand Down Expand Up @@ -3999,14 +3999,14 @@ class SumVec(Valid[list[int], list[int], F]):
def encode(self, measurement: list[int]) -> list[F]:
encoded = []
for val in measurement:
encoded += self.field.encode_into_vit_vec(
encoded += self.field.encode_into_bit_vec(
val, self.bits)
return encoded

def truncate(self, meas: list[F]) -> list[F]:
truncated = []
for i in range(self.length):
truncated.append(self.field.decode_from_vit_vec(
truncated.append(self.field.decode_from_bit_vec(
meas[i * self.bits: (i + 1) * self.bits]
))
return truncated
Expand Down Expand Up @@ -4275,7 +4275,7 @@ class MultihotCountVec(Valid[list[int], list[int], F]):
count_vec = meas[:self.length]
weight = sum(count_vec, self.field(0))
weight_reported = \
self.field.decode_from_vit_vec(meas[self.length:])
self.field.decode_from_bit_vec(meas[self.length:])
weight_check = self.offset*shares_inv + weight - \
weight_reported

Expand All @@ -4293,7 +4293,7 @@ class MultihotCountVec(Valid[list[int], list[int], F]):

encoded = []
encoded += count_vec
encoded += self.field.encode_into_vit_vec(
encoded += self.field.encode_into_bit_vec(
(self.offset + weight_reported).int(),
self.bits_for_weight)
return encoded
Expand Down
4 changes: 2 additions & 2 deletions poc/tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def run_field_test(self, cls: type[Field]) -> None:
vals = [i for i in range(15)]
bits = 4
for val in vals:
encoded = cls.encode_into_vit_vec(val, bits)
self.assertTrue(cls.decode_from_vit_vec(
encoded = cls.encode_into_bit_vec(val, bits)
self.assertTrue(cls.decode_from_bit_vec(
encoded).int() == val)

def run_ntt_field_test(self, cls: type[NttField]) -> None:
Expand Down
6 changes: 3 additions & 3 deletions poc/vdaf_poc/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ def decode_vec(cls, encoded: bytes) -> list[Self]:
vec.append(cls(x))
return vec

# NOTE: The encode_into_vit_vec() and decode_from_vit_vec()
# NOTE: The encode_into_bit_vec() and decode_from_bit_vec()
# methods are excerpted in the document, de-indented, as the figure
# {{field-bit-rep}}. Their width should be limited to 69 columns
# after de-indenting, or 73 columns before de-indenting, to avoid
# warnings from xml2rfc.
# ===================================================================
@classmethod
def encode_into_vit_vec(
def encode_into_bit_vec(
cls,
val: int,
bits: int) -> list[Self]:
Expand All @@ -99,7 +99,7 @@ def encode_into_vit_vec(
return encoded

@classmethod
def decode_from_vit_vec(cls, vec: list[Self]) -> Self:
def decode_from_bit_vec(cls, vec: list[Self]) -> Self:
"""
Decode the field element from the bit representation, expressed
as a vector of field elements `vec`.
Expand Down
18 changes: 9 additions & 9 deletions poc/vdaf_poc/flp_bbcggi19.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ def eval(
count_vec = meas[:self.length]
weight = sum(count_vec, self.field(0))
weight_reported = \
self.field.decode_from_vit_vec(meas[self.length:])
self.field.decode_from_bit_vec(meas[self.length:])
weight_check = self.offset*shares_inv + weight - \
weight_reported

Expand All @@ -873,7 +873,7 @@ def encode(self, measurement: list[int]) -> list[F]:

encoded = []
encoded += count_vec
encoded += self.field.encode_into_vit_vec(
encoded += self.field.encode_into_bit_vec(
(self.offset + weight_reported).int(),
self.bits_for_weight)
return encoded
Expand Down Expand Up @@ -982,14 +982,14 @@ def encode(self, measurement: list[int]) -> list[F]:
'entry of measurement vector is out of range'
)

encoded += self.field.encode_into_vit_vec(
encoded += self.field.encode_into_bit_vec(
val, self.bits)
return encoded

def truncate(self, meas: list[F]) -> list[F]:
truncated = []
for i in range(self.length):
truncated.append(self.field.decode_from_vit_vec(
truncated.append(self.field.decode_from_bit_vec(
meas[i * self.bits: (i + 1) * self.bits]
))
return truncated
Expand Down Expand Up @@ -1070,25 +1070,25 @@ def eval(
out.append(self.GADGETS[0].eval(self.field, [b]))

range_check = self.offset * shares_inv + \
self.field.decode_from_vit_vec(meas[:self.bits]) - \
self.field.decode_from_vit_vec(meas[self.bits:])
self.field.decode_from_bit_vec(meas[:self.bits]) - \
self.field.decode_from_bit_vec(meas[self.bits:])
out.append(range_check)
return out

def encode(self, measurement: int) -> list[F]:
encoded = []
encoded += self.field.encode_into_vit_vec(
encoded += self.field.encode_into_bit_vec(
measurement,
self.bits
)
encoded += self.field.encode_into_vit_vec(
encoded += self.field.encode_into_bit_vec(
measurement + self.offset.int(),
self.bits
)
return encoded

def truncate(self, meas: list[F]) -> list[F]:
return [self.field.decode_from_vit_vec(meas[:self.bits])]
return [self.field.decode_from_bit_vec(meas[:self.bits])]

def decode(self, output: list[F], _num_measurements: int) -> int:
return output[0].int()
Expand Down

0 comments on commit b0decf1

Please sign in to comment.