Skip to content

Commit

Permalink
Remove curve name from the Fields API
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhargavasomu committed Mar 4, 2019
1 parent 0f19487 commit 8bdebb2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 46 deletions.
16 changes: 0 additions & 16 deletions py_ecc/fields/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,20 @@
"bn128_FQ",
(FQ,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
}
)
bn128_FQP = type(
"bn128_FQP",
(FQP,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
}
)
bn128_FQ2 = type(
"bn128_FQ2",
(FQ2,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
'FQ2_MODULUS_COEFFS': field_properties["bn128"]["fq2_modulus_coeffs"],
}
Expand All @@ -48,7 +45,6 @@
"bn128_FQ12",
(FQ12,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
'FQ12_MODULUS_COEFFS': field_properties["bn128"]["fq12_modulus_coeffs"],
}
Expand All @@ -58,23 +54,20 @@
"bls12_381_FQ",
(FQ,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
}
)
bls12_381_FQP = type(
"bls12_381_FQP",
(FQP,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
}
)
bls12_381_FQ2 = type(
"bls12_381_FQ2",
(FQ2,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
'FQ2_MODULUS_COEFFS': field_properties["bls12_381"]["fq2_modulus_coeffs"],
}
Expand All @@ -83,7 +76,6 @@
"bls12_381_FQ12",
(FQ12,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
'FQ12_MODULUS_COEFFS': field_properties["bls12_381"]["fq12_modulus_coeffs"],
}
Expand All @@ -93,23 +85,20 @@
"optimized_bn128_FQ",
(optimized_FQ,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
}
)
optimized_bn128_FQP = type(
"optimized_bn128_FQP",
(optimized_FQP,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
}
)
optimized_bn128_FQ2 = type(
"optimized_bn128_FQ2",
(optimized_FQ2,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
'FQ2_MODULUS_COEFFS': field_properties["bn128"]["fq2_modulus_coeffs"],
}
Expand All @@ -118,7 +107,6 @@
"optimized_bn128_FQ12",
(optimized_FQ12,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
'FQ12_MODULUS_COEFFS': field_properties["bn128"]["fq12_modulus_coeffs"],
}
Expand All @@ -128,23 +116,20 @@
"optimized_bls12_381_FQ",
(optimized_FQ,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
}
)
optimized_bls12_381_FQP = type(
"optimized_bls12_381_FQP",
(optimized_FQP,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
}
)
optimized_bls12_381_FQ2 = type(
"optimized_bls12_381_FQ2",
(optimized_FQ2,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
'FQ2_MODULUS_COEFFS': field_properties["bls12_381"]["fq2_modulus_coeffs"],
}
Expand All @@ -153,7 +138,6 @@
"optimized_bls12_381_FQ12",
(optimized_FQ12,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
'FQ12_MODULUS_COEFFS': field_properties["bls12_381"]["fq12_modulus_coeffs"],
}
Expand Down
19 changes: 3 additions & 16 deletions py_ecc/fields/field_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ class FQ(object):
"""
n = None # type: int
field_modulus = None
# curve_name can be either 'bn128' or 'bls12_381'
# This is needed to obtain field_modulus, FQ2_MODULUS_COEFFS
# and FQ12_MODULUS_COEFFS from the curve properties
curve_name = None

def __init__(self, val: IntOrFQ) -> None:
if self.curve_name is None:
raise AttributeError("Curve Name hasn't been specified")
if self.field_modulus is None:
raise AttributeError("Field Modulus hasn't been specified")

Expand Down Expand Up @@ -187,26 +181,23 @@ class FQP(object):
A class for elements in polynomial extension fields
"""
degree = 0
curve_name = None
field_modulus = None

def __init__(self,
coeffs: Sequence[IntOrFQ],
modulus_coeffs: Sequence[IntOrFQ]=None) -> None:
if self.curve_name is None:
raise AttributeError("Curve Name hasn't been specified")
if self.field_modulus is None:
raise AttributeError("Field Modulus hasn't been specified")

if len(coeffs) != len(modulus_coeffs):
raise Exception(
"coeffs and modulus_coeffs aren't of the same length"
)
# Encoding all coefficients in type FQ (in regards to the curve name too)
# Encoding all coefficients in the corresponding type FQ
self.FQP_corresponding_FQ_class = type(
"FQP_corresponding_FQ_class_" + self.curve_name,
"FQP_corresponding_FQ_class",
(FQ,),
{'curve_name': self.curve_name, 'field_modulus': self.field_modulus}
{'field_modulus': self.field_modulus}
)
self.coeffs = tuple(self.FQP_corresponding_FQ_class(c) for c in coeffs)
# The coefficients of the modulus, without the leading [1]
Expand Down Expand Up @@ -353,8 +344,6 @@ class FQ2(FQP):
FQ2_MODULUS_COEFFS = None

def __init__(self, coeffs: Sequence[IntOrFQ]) -> None:
if self.curve_name is None:
raise AttributeError("Curve Name hasn't been specified")
if self.FQ2_MODULUS_COEFFS is None:
raise AttributeError("FQ2 Modulus Coeffs haven't been specified")

Expand All @@ -369,8 +358,6 @@ class FQ12(FQP):
FQ12_MODULUS_COEFFS = None

def __init__(self, coeffs: Sequence[IntOrFQ]) -> None:
if self.curve_name is None:
raise AttributeError("Curve Name hasn't been specified")
if self.FQ12_MODULUS_COEFFS is None:
raise AttributeError("FQ12 Modulus Coeffs haven't been specified")

Expand Down
15 changes: 1 addition & 14 deletions py_ecc/fields/optimized_field_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ class FQ(object):
"""
n = None # type: int
field_modulus = None
# curve_name can be either 'bn128' or 'bls12_381'
# This is needed to obtain field_modulus, FQ2_MODULUS_COEFFS
# and FQ12_MODULUS_COEFFS from the curve properties
curve_name = None

def __init__(self, val: IntOrFQ) -> None:
if self.curve_name is None:
raise AttributeError("Curve Name hasn't been specified")
if self.field_modulus is None:
raise AttributeError("Field Modulus hasn't been specified")

Expand Down Expand Up @@ -187,15 +181,12 @@ class FQP(object):
A class for elements in polynomial extension fields
"""
degree = 0 # type: int
mc_tuples = None # type: List[Tuple[int, int]]
curve_name = None
field_modulus = None
mc_tuples = None # type: List[Tuple[int, int]]

def __init__(self,
coeffs: Sequence[IntOrFQ],
modulus_coeffs: Sequence[IntOrFQ]=None) -> None:
if self.curve_name is None:
raise AttributeError("Curve Name hasn't been specified")
if self.field_modulus is None:
raise AttributeError("Field Modulus hasn't been specified")

Expand Down Expand Up @@ -372,8 +363,6 @@ class FQ2(FQP):
FQ2_MODULUS_COEFFS = None

def __init__(self, coeffs: Sequence[IntOrFQ]) -> None:
if self.curve_name is None:
raise AttributeError("Curve Name hasn't been specified")
if self.FQ2_MODULUS_COEFFS is None:
raise AttributeError("FQ2 Modulus Coeffs haven't been specified")

Expand All @@ -389,8 +378,6 @@ class FQ12(FQP):
FQ12_MODULUS_COEFFS = None

def __init__(self, coeffs: Sequence[IntOrFQ]) -> None:
if self.curve_name is None:
raise AttributeError("Curve Name hasn't been specified")
if self.FQ12_MODULUS_COEFFS is None:
raise AttributeError("FQ12 Modulus Coeffs haven't been specified")

Expand Down

0 comments on commit 8bdebb2

Please sign in to comment.