Merge pull request #3619 from asn-d6/peerdas_poly_degree_overflow
PeerDAS: Check for degree overflow in multiply_polynomialcoeff()
This commit is contained in:
commit
46b118a212
|
@ -4,3 +4,5 @@
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# `uint64(2**6)` (= 64)
|
# `uint64(2**6)` (= 64)
|
||||||
FIELD_ELEMENTS_PER_CELL: 64
|
FIELD_ELEMENTS_PER_CELL: 64
|
||||||
|
# `uint64(2 * 4096)` (= 8192)
|
||||||
|
FIELD_ELEMENTS_PER_EXT_BLOB: 8192
|
||||||
|
|
|
@ -4,3 +4,5 @@
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# `uint64(2**6)` (= 64)
|
# `uint64(2**6)` (= 64)
|
||||||
FIELD_ELEMENTS_PER_CELL: 64
|
FIELD_ELEMENTS_PER_CELL: 64
|
||||||
|
# `uint64(2 * 4096)` (= 8192)
|
||||||
|
FIELD_ELEMENTS_PER_EXT_BLOB: 8192
|
||||||
|
|
|
@ -17,4 +17,5 @@ from eth2spec.deneb import {preset_name} as deneb
|
||||||
def hardcoded_custom_type_dep_constants(cls, spec_object) -> Dict[str, str]:
|
def hardcoded_custom_type_dep_constants(cls, spec_object) -> Dict[str, str]:
|
||||||
return {
|
return {
|
||||||
'FIELD_ELEMENTS_PER_CELL': spec_object.preset_vars['FIELD_ELEMENTS_PER_CELL'].value,
|
'FIELD_ELEMENTS_PER_CELL': spec_object.preset_vars['FIELD_ELEMENTS_PER_CELL'].value,
|
||||||
|
'FIELD_ELEMENTS_PER_EXT_BLOB': spec_object.preset_vars['FIELD_ELEMENTS_PER_EXT_BLOB'].value,
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ Public functions MUST accept raw bytes as input and perform the required cryptog
|
||||||
|
|
||||||
| Name | SSZ equivalent | Description |
|
| Name | SSZ equivalent | Description |
|
||||||
| - | - | - |
|
| - | - | - |
|
||||||
| `PolynomialCoeff` | `List[BLSFieldElement, 2 * FIELD_ELEMENTS_PER_BLOB]` | A polynomial in coefficient form |
|
| `PolynomialCoeff` | `List[BLSFieldElement, FIELD_ELEMENTS_PER_EXT_BLOB]` | A polynomial in coefficient form |
|
||||||
| `Cell` | `Vector[BLSFieldElement, FIELD_ELEMENTS_PER_CELL]` | The unit of blob data that can come with their own KZG proofs |
|
| `Cell` | `Vector[BLSFieldElement, FIELD_ELEMENTS_PER_CELL]` | The unit of blob data that can come with their own KZG proofs |
|
||||||
| `CellID` | `uint64` | Cell identifier |
|
| `CellID` | `uint64` | Cell identifier |
|
||||||
|
|
||||||
|
@ -196,12 +196,15 @@ def multiply_polynomialcoeff(a: PolynomialCoeff, b: PolynomialCoeff) -> Polynomi
|
||||||
"""
|
"""
|
||||||
Multiplies the coefficient form polynomials ``a`` and ``b``
|
Multiplies the coefficient form polynomials ``a`` and ``b``
|
||||||
"""
|
"""
|
||||||
|
assert len(a) + len(b) <= FIELD_ELEMENTS_PER_EXT_BLOB
|
||||||
|
|
||||||
r = [0]
|
r = [0]
|
||||||
for power, coef in enumerate(a):
|
for power, coef in enumerate(a):
|
||||||
summand = [0] * power + [int(coef) * int(x) % BLS_MODULUS for x in b]
|
summand = [0] * power + [int(coef) * int(x) % BLS_MODULUS for x in b]
|
||||||
r = add_polynomialcoeff(r, summand)
|
r = add_polynomialcoeff(r, summand)
|
||||||
return r
|
return r
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `divide_polynomialcoeff`
|
#### `divide_polynomialcoeff`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|
|
@ -2,6 +2,7 @@ import random
|
||||||
from eth2spec.test.context import (
|
from eth2spec.test.context import (
|
||||||
spec_test,
|
spec_test,
|
||||||
single_phase,
|
single_phase,
|
||||||
|
expect_assertion_error,
|
||||||
with_eip7594_and_later,
|
with_eip7594_and_later,
|
||||||
)
|
)
|
||||||
from eth2spec.test.helpers.sharding import (
|
from eth2spec.test.helpers.sharding import (
|
||||||
|
@ -105,3 +106,19 @@ def test_recover_polynomial(spec):
|
||||||
# Now flatten the cells and check that they match the entirety of the recovered data
|
# Now flatten the cells and check that they match the entirety of the recovered data
|
||||||
flattened_cells = [x for xs in cells for x in xs]
|
flattened_cells = [x for xs in cells for x in xs]
|
||||||
assert flattened_cells == recovered_data
|
assert flattened_cells == recovered_data
|
||||||
|
|
||||||
|
|
||||||
|
@with_eip7594_and_later
|
||||||
|
@spec_test
|
||||||
|
@single_phase
|
||||||
|
def test_multiply_polynomial_degree_overflow(spec):
|
||||||
|
rng = random.Random(5566)
|
||||||
|
|
||||||
|
# Perform a legitimate-but-maxed-out polynomial multiplication
|
||||||
|
poly1_coeff = [rng.randint(0, BLS_MODULUS - 1) for _ in range(spec.FIELD_ELEMENTS_PER_BLOB)]
|
||||||
|
poly2_coeff = [rng.randint(0, BLS_MODULUS - 1) for _ in range(spec.FIELD_ELEMENTS_PER_BLOB)]
|
||||||
|
_ = spec.multiply_polynomialcoeff(poly1_coeff, poly2_coeff)
|
||||||
|
|
||||||
|
# Now overflow the degree by pumping the degree of one of the inputs by one
|
||||||
|
poly2_coeff = [rng.randint(0, BLS_MODULUS - 1) for _ in range(spec.FIELD_ELEMENTS_PER_BLOB + 1)]
|
||||||
|
expect_assertion_error(lambda: spec.multiply_polynomialcoeff(poly1_coeff, poly2_coeff))
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
from eth2spec.test.context import (
|
||||||
|
single_phase,
|
||||||
|
spec_test,
|
||||||
|
with_eip7594_and_later,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@with_eip7594_and_later
|
||||||
|
@spec_test
|
||||||
|
@single_phase
|
||||||
|
def test_polynomical_commitments_sampling(spec):
|
||||||
|
assert spec.FIELD_ELEMENTS_PER_EXT_BLOB == 2 * spec.FIELD_ELEMENTS_PER_BLOB
|
Loading…
Reference in New Issue