Skip to content

Commit adb5134

Browse files
authored
Merge branch 'dev' into kzg_multi_verify
2 parents 4086a09 + 89f2eae commit adb5134

File tree

8 files changed

+68
-12
lines changed

8 files changed

+68
-12
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ def run(self):
11691169
"pycryptodome==3.15.0",
11701170
"py_ecc==6.0.0",
11711171
"milagro_bls_binding==1.9.0",
1172-
"remerkleable==0.1.25",
1172+
"remerkleable==0.1.27",
11731173
"trie==2.0.2",
11741174
RUAMEL_YAML_VERSION,
11751175
"lru-dict==1.1.8",

specs/capella/beacon-chain.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class BeaconState(Container):
242242
current_sync_committee: SyncCommittee
243243
next_sync_committee: SyncCommittee
244244
# Execution
245-
latest_execution_payload_header: ExecutionPayloadHeader
245+
latest_execution_payload_header: ExecutionPayloadHeader # [Modified in Capella]
246246
# Withdrawals
247247
next_withdrawal_index: WithdrawalIndex # [New in Capella]
248248
next_withdrawal_validator_index: ValidatorIndex # [New in Capella]

specs/deneb/beacon-chain.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ class ExecutionPayload(Container):
108108
timestamp: uint64
109109
extra_data: ByteList[MAX_EXTRA_DATA_BYTES]
110110
base_fee_per_gas: uint256
111-
excess_data_gas: uint256 # [New in Deneb]
112111
# Extra payload fields
113112
block_hash: Hash32 # Hash of execution block
114113
transactions: List[Transaction, MAX_TRANSACTIONS_PER_PAYLOAD]
115114
withdrawals: List[Withdrawal, MAX_WITHDRAWALS_PER_PAYLOAD]
115+
excess_data_gas: uint256 # [New in Deneb]
116116
```
117117

118118
#### `ExecutionPayloadHeader`
@@ -132,11 +132,11 @@ class ExecutionPayloadHeader(Container):
132132
timestamp: uint64
133133
extra_data: ByteList[MAX_EXTRA_DATA_BYTES]
134134
base_fee_per_gas: uint256
135-
excess_data_gas: uint256 # [New in Deneb]
136135
# Extra payload fields
137136
block_hash: Hash32 # Hash of execution block
138137
transactions_root: Root
139138
withdrawals_root: Root
139+
excess_data_gas: uint256 # [New in Deneb]
140140
```
141141

142142
## Helper functions
@@ -230,10 +230,10 @@ def process_execution_payload(state: BeaconState, payload: ExecutionPayload, exe
230230
timestamp=payload.timestamp,
231231
extra_data=payload.extra_data,
232232
base_fee_per_gas=payload.base_fee_per_gas,
233-
excess_data_gas=payload.excess_data_gas, # [New in Deneb]
234233
block_hash=payload.block_hash,
235234
transactions_root=hash_tree_root(payload.transactions),
236235
withdrawals_root=hash_tree_root(payload.withdrawals),
236+
excess_data_gas=payload.excess_data_gas, # [New in Deneb]
237237
)
238238
```
239239

specs/deneb/polynomial-commitments.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,23 +440,61 @@ def compute_kzg_proof(blob: Blob, z: Bytes32) -> KZGProof:
440440
return compute_kzg_proof_impl(polynomial, bytes_to_bls_field(z))
441441
```
442442

443+
#### `compute_quotient_eval_within_domain`
444+
445+
```python
446+
def compute_quotient_eval_within_domain(z: BLSFieldElement,
447+
polynomial: Polynomial,
448+
y: BLSFieldElement
449+
) -> BLSFieldElement:
450+
"""
451+
Given `y == p(z)` for a polynomial `p(x)`, compute `q(z)`: the KZG quotient polynomial evaluated at `z` for the
452+
special case where `z` is in `ROOTS_OF_UNITY`.
453+
454+
For more details, read https://dankradfeist.de/ethereum/2021/06/18/pcs-multiproofs.html section "Dividing
455+
when one of the points is zero". The code below computes q(x_m) for the roots of unity special case.
456+
"""
457+
roots_of_unity_brp = bit_reversal_permutation(ROOTS_OF_UNITY)
458+
result = 0
459+
for i, omega_i in enumerate(roots_of_unity_brp):
460+
if omega_i == z: # skip the evaluation point in the sum
461+
continue
462+
463+
f_i = int(BLS_MODULUS) + int(polynomial[i]) - int(y) % BLS_MODULUS
464+
numerator = f_i * int(omega_i) % BLS_MODULUS
465+
denominator = int(z) * (int(BLS_MODULUS) + int(z) - int(omega_i)) % BLS_MODULUS
466+
result += div(BLSFieldElement(numerator), BLSFieldElement(denominator))
467+
468+
return BLSFieldElement(result % BLS_MODULUS)
469+
```
470+
443471
#### `compute_kzg_proof_impl`
444472

445473
```python
446474
def compute_kzg_proof_impl(polynomial: Polynomial, z: BLSFieldElement) -> KZGProof:
447475
"""
448476
Helper function for compute_kzg_proof() and compute_aggregate_kzg_proof().
449477
"""
478+
roots_of_unity_brp = bit_reversal_permutation(ROOTS_OF_UNITY)
479+
480+
# For all x_i, compute p(x_i) - p(z)
450481
y = evaluate_polynomial_in_evaluation_form(polynomial, z)
451482
polynomial_shifted = [BLSFieldElement((int(p) - int(y)) % BLS_MODULUS) for p in polynomial]
452483

453-
# Make sure we won't divide by zero during division
454-
assert z not in ROOTS_OF_UNITY
484+
# For all x_i, compute (x_i - z)
455485
denominator_poly = [BLSFieldElement((int(x) - int(z)) % BLS_MODULUS)
456486
for x in bit_reversal_permutation(ROOTS_OF_UNITY)]
457487

458-
# Calculate quotient polynomial by doing point-by-point division
459-
quotient_polynomial = [div(a, b) for a, b in zip(polynomial_shifted, denominator_poly)]
488+
# Compute the quotient polynomial directly in evaluation form
489+
quotient_polynomial = [BLSFieldElement(0)] * FIELD_ELEMENTS_PER_BLOB
490+
for i, (a, b) in enumerate(zip(polynomial_shifted, denominator_poly)):
491+
if b == 0:
492+
# The denominator is zero hence `z` is a root of unity: we must handle it as a special case
493+
quotient_polynomial[i] = compute_quotient_eval_within_domain(roots_of_unity_brp[i], polynomial, y)
494+
else:
495+
# Compute: q(x_i) = (p(x_i) - p(z)) / (x_i - z).
496+
quotient_polynomial[i] = div(a, b)
497+
460498
return KZGProof(g1_lincomb(bit_reversal_permutation(KZG_SETUP_LAGRANGE), quotient_polynomial))
461499
```
462500

tests/core/pyspec/eth2spec/test/eip4844/transition/__init__.py renamed to tests/core/pyspec/eth2spec/test/deneb/transition/__init__.py

File renamed without changes.

tests/core/pyspec/eth2spec/test/eip4844/transition/test_operations.py renamed to tests/core/pyspec/eth2spec/test/deneb/transition/test_operations.py

File renamed without changes.

tests/core/pyspec/eth2spec/test/deneb/unittests/polynomial_commitments/test_polynomial_commitments.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,23 @@ def test_barycentric_within_domain(spec, state):
8787
# The two evaluations should be agree and p(z) should also be the i-th "coefficient" of the polynomial in
8888
# evaluation form
8989
assert p_z_coeff == p_z_eval == poly_eval[i]
90+
91+
92+
@with_deneb_and_later
93+
@spec_state_test
94+
def test_compute_kzg_proof_within_domain(spec, state):
95+
"""
96+
Create and verify KZG proof that p(z) == y
97+
where z is in the domain of our KZG scheme (i.e. a relevant root of unity).
98+
"""
99+
blob = get_sample_blob(spec)
100+
commitment = spec.blob_to_kzg_commitment(blob)
101+
polynomial = spec.blob_to_polynomial(blob)
102+
103+
roots_of_unity_brp = spec.bit_reversal_permutation(spec.ROOTS_OF_UNITY)
104+
105+
for i, z in enumerate(roots_of_unity_brp):
106+
proof = spec.compute_kzg_proof_impl(polynomial, z)
107+
108+
y = spec.evaluate_polynomial_in_evaluation_form(polynomial, z)
109+
assert spec.verify_kzg_proof_impl(commitment, z, y, proof)

tests/core/pyspec/eth2spec/test/helpers/capella/fork.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ def run_fork_test(post_spec, pre_state):
2929
'inactivity_scores',
3030
# Sync
3131
'current_sync_committee', 'next_sync_committee',
32-
# Execution
33-
'latest_execution_payload_header',
3432
]
3533
for field in stable_fields:
3634
assert getattr(pre_state, field) == getattr(post_state, field)
3735

3836
# Modified fields
39-
modified_fields = ['fork']
37+
modified_fields = ['fork', 'latest_execution_payload_header']
4038
for field in modified_fields:
4139
assert getattr(pre_state, field) != getattr(post_state, field)
4240

0 commit comments

Comments
 (0)