diff --git a/py_ecc/optimized_bls12_381/optimized_field_elements.py b/py_ecc/optimized_bls12_381/optimized_field_elements.py
index 3f537bb..b65f138 100644
--- a/py_ecc/optimized_bls12_381/optimized_field_elements.py
+++ b/py_ecc/optimized_bls12_381/optimized_field_elements.py
@@ -239,7 +239,10 @@ class FQP(object):
 # The quadratic extension field
 class FQ2(FQP):
     def __init__(self, coeffs):
-        self.coeffs = tuple(coeffs)
+        if isinstance(coeffs[0], int):
+            self.coeffs = tuple(coeff % field_modulus for coeff in coeffs)
+        else:
+            self.coeffs = tuple(coeffs)
         self.modulus_coeffs = (1, 0)
         self.mc_tuples = [(0, 1)]
         self.degree = 2
@@ -249,7 +252,10 @@ class FQ2(FQP):
 # The 12th-degree extension field
 class FQ12(FQP):
     def __init__(self, coeffs):
-        self.coeffs = tuple(coeffs)
+        if isinstance(coeffs[0], int):
+            self.coeffs = tuple(coeff % field_modulus for coeff in coeffs)
+        else:
+            self.coeffs = tuple(coeffs)
         self.modulus_coeffs = FQ12_modulus_coeffs
         self.mc_tuples = FQ12_mc_tuples
         self.degree = 12
diff --git a/py_ecc/optimized_bn128/optimized_field_elements.py b/py_ecc/optimized_bn128/optimized_field_elements.py
index b414c02..b830b1a 100644
--- a/py_ecc/optimized_bn128/optimized_field_elements.py
+++ b/py_ecc/optimized_bn128/optimized_field_elements.py
@@ -150,9 +150,13 @@ class FQP(object):
 
     def __init__(self,
                  coeffs: Sequence[IntOrFQ],
-                 modulus_coeffs: Sequence[IntOrFQ]=None) -> None:
+                 modulus_coeffs: Sequence[IntOrFQ] = None) -> None:
         assert len(coeffs) == len(modulus_coeffs)
-        self.coeffs = coeffs
+
+        if isinstance(coeffs[0], int):
+            self.coeffs = [coeff % field_modulus for coeff in coeffs]
+        else:
+            self.coeffs = list(coeffs)
         # The coefficients of the modulus, without the leading [1]
         self.modulus_coeffs = modulus_coeffs
         # The degree of the extension field
@@ -225,8 +229,8 @@ class FQP(object):
     def inv(self) -> "FQP":
         lm, hm = [1] + [0] * self.degree, [0] * (self.degree + 1)
         low, high = (
+            self.coeffs + [0],
             # Ignore mypy yelling about the inner types for the lists being incompatible
-            cast(List[IntOrFQ], list(self.coeffs + [0])),  # type: ignore
             cast(List[IntOrFQ], list(self.modulus_coeffs + [1])),  # type: ignore
         )
         low, high = list(self.coeffs + [0]), self.modulus_coeffs + [1]  # type: ignore

FQP initialization should take the mod of input coefficients
Full context: https://github.com/ethereum/eth2.0-specs/issues/508

### What is wrong?

For BN and BLS, FQP object should take the modulo of the input during initialization.

Test case:

```python
from py_ecc.optimized_bls12_381 import FQ, FQ2

x = FQ(-1)
y = FQ2([-1,-1])

print(x) # 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786
print(y) # (-1, -1)
```

This is used in  `modular_squareroot` part of Eth2.0 spec (https://github.com/ethereum/eth2.0-specs/blob/928f9772fa51ed2e251b99c4795097da976c4bde/specs/bls_signature.md#modular_squareroot) and Trinity (https://github.com/ethereum/trinity/blob/a1b0f058e7bc8e385c8dac3164c49098967fd5bb/eth2/_utils/bls.py#L63-L77)

### How can it be fixed

Take the mod of the inputs in FQP `__init__`

https://github.com/ethereum/py_ecc/blob/e9c42c76f1cc4f535dedec01b4c7ab2a59e46119/py_ecc/optimized_bls12_381/optimized_field_elements.py#L126-L133

Like it's done for FQ

https://github.com/ethereum/py_ecc/blob/e9c42c76f1cc4f535dedec01b4c7ab2a59e46119/py_ecc/optimized_bls12_381/optimized_field_elements.py#L25-L31

diff --git a/tests/test_bn128_and_bls12_381.py b/tests/test_bn128_and_bls12_381.py
index 09be997..93342b7 100644
--- a/tests/test_bn128_and_bls12_381.py
+++ b/tests/test_bn128_and_bls12_381.py
@@ -29,6 +29,7 @@ def FQ12(lib):
 def field_modulus(lib):
     return lib.field_modulus
 
+
 @pytest.fixture
 def G1(lib):
     return lib.G1
@@ -124,6 +125,7 @@ def test_FQ_object(FQ, field_modulus):
     assert FQ(2) / FQ(7) + FQ(9) / FQ(7) == FQ(11) / FQ(7)
     assert FQ(2) * FQ(7) + FQ(9) * FQ(7) == FQ(11) * FQ(7)
     assert FQ(9) ** field_modulus == FQ(9)
+    assert FQ(-1).n > 0
 
 
 def test_FQ2_object(FQ2, field_modulus):
@@ -131,11 +133,18 @@ def test_FQ2_object(FQ2, field_modulus):
     f = FQ2([1, 2])
     fpx = FQ2([2, 2])
     one = FQ2.one()
+    z1, z2 = FQ2([-1, -1]).coeffs
     assert x + f == fpx
     assert f / f == one
     assert one / f + x / f == (one + x) / f
     assert one * f + x * f == (one + x) * f
     assert x ** (field_modulus ** 2 - 1) == one
+    if isinstance(z1, int):
+        assert z1 > 0
+        assert z2 > 0
+    else:
+        assert z1.n > 0
+        assert z2.n > 0
 
 
 def test_FQ12_object(FQ12, field_modulus):
@@ -143,10 +152,15 @@ def test_FQ12_object(FQ12, field_modulus):
     f = FQ12([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
     fpx = FQ12([2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
     one = FQ12.one()
+    zs = FQ12([-1]*12).coeffs
     assert x + f == fpx
     assert f / f == one
     assert one / f + x / f == (one + x) / f
     assert one * f + x * f == (one + x) * f
+    if isinstance(zs[0], int):
+        assert all(z > 0 for z in zs)
+    else:
+        assert all(z.n > 0 for z in zs)
     # This check takes too long
     # assert x ** (field_modulus ** 12 - 1) == one
 
@@ -184,6 +198,7 @@ def test_Z1_object(add, eq, double, FQ, G1, is_inf, multiply, neg, twist, Z1):
     assert eq(Z1, multiply(Z1, 3))
     assert is_inf(neg(Z1))
 
+
 def test_Z2_object(add, eq, double, FQ2, G2, is_inf, multiply, neg, twist, Z2):
     assert eq(G2, add(G2, Z2))
     assert eq(Z2, double(Z2))
@@ -194,6 +209,7 @@ def test_Z2_object(add, eq, double, FQ2, G2, is_inf, multiply, neg, twist, Z2):
     assert is_inf(neg(Z2))
     assert is_inf(twist(Z2))
 
+
 def test_none_point(lib, neg, twist):
     if lib not in [optimized_bn128, optimized_bls12_381]:
         pytest.skip()

pip install -e .
parse_log_pytest
pytest
pytest pytest-xdist
apt-get update apt-get install -y gcc
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
certifi==2021.5.30
execnet==1.9.0
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1631916693255/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
-e git+https://github.com/ethereum/py_ecc.git@e9c42c76f1cc4f535dedec01b4c7ab2a59e46119#egg=py_ecc
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
pytest-xdist==3.0.2
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: py_ecc
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib-metadata=4.8.1=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - execnet==1.9.0
      - pytest-xdist==3.0.2
prefix: /opt/conda/envs/py_ecc

tests/test_bn128_and_bls12_381.py::test_FQ2_object[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_FQ2_object[py_ecc.optimized_bls12_381] tests/test_bn128_and_bls12_381.py::test_FQ12_object[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_FQ12_object[py_ecc.optimized_bls12_381]
tests/test_bn128_and_bls12_381.py::test_FQ_object[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_FQ_object[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_FQ_object[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_FQ_object[py_ecc.optimized_bls12_381] tests/test_bn128_and_bls12_381.py::test_FQ2_object[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_FQ2_object[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_FQ12_object[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_FQ12_object[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_G1_object[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_G1_object[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_G1_object[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_G1_object[py_ecc.optimized_bls12_381] tests/test_bn128_and_bls12_381.py::test_G2_object[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_G2_object[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_G2_object[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_G2_object[py_ecc.optimized_bls12_381] tests/test_bn128_and_bls12_381.py::test_G12_object[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_G12_object[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_G12_object[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_G12_object[py_ecc.optimized_bls12_381] tests/test_bn128_and_bls12_381.py::test_Z1_object[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_Z1_object[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_Z1_object[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_Z1_object[py_ecc.optimized_bls12_381] tests/test_bn128_and_bls12_381.py::test_Z2_object[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_Z2_object[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_Z2_object[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_Z2_object[py_ecc.optimized_bls12_381] tests/test_bn128_and_bls12_381.py::test_none_point[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_none_point[py_ecc.optimized_bls12_381] tests/test_bn128_and_bls12_381.py::test_pairing_negative_G1[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_pairing_negative_G1[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_pairing_negative_G1[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_pairing_negative_G1[py_ecc.optimized_bls12_381] tests/test_bn128_and_bls12_381.py::test_pairing_negative_G2[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_pairing_negative_G2[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_pairing_negative_G2[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_pairing_negative_G2[py_ecc.optimized_bls12_381] tests/test_bn128_and_bls12_381.py::test_pairing_output_order[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_pairing_output_order[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_pairing_output_order[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_pairing_output_order[py_ecc.optimized_bls12_381] tests/test_bn128_and_bls12_381.py::test_pairing_bilinearity_on_G1[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_pairing_bilinearity_on_G1[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_pairing_bilinearity_on_G1[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_pairing_bilinearity_on_G1[py_ecc.optimized_bls12_381] tests/test_bn128_and_bls12_381.py::test_pairing_is_non_degenerate[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_pairing_is_non_degenerate[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_pairing_is_non_degenerate[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_pairing_is_non_degenerate[py_ecc.optimized_bls12_381] tests/test_bn128_and_bls12_381.py::test_pairing_bilinearity_on_G2[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_pairing_bilinearity_on_G2[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_pairing_bilinearity_on_G2[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_pairing_bilinearity_on_G2[py_ecc.optimized_bls12_381] tests/test_bn128_and_bls12_381.py::test_pairing_composit_check[py_ecc.bn128] tests/test_bn128_and_bls12_381.py::test_pairing_composit_check[py_ecc.optimized_bn128] tests/test_bn128_and_bls12_381.py::test_pairing_composit_check[py_ecc.bls12_381] tests/test_bn128_and_bls12_381.py::test_pairing_composit_check[py_ecc.optimized_bls12_381]
py_ecc/optimized_bls12_381/optimized_field_elements.py py_ecc/optimized_bn128/optimized_field_elements.py
py_ecc/optimized_bls12_381/optimized_field_elements.py py_ecc/optimized_bn128/optimized_field_elements.py