Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-7594: Add cryptography specs for sampling #3557

Merged
merged 29 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
94ecce7
Add polynomial commitments for sampling
dankrad Dec 4, 2023
0d4007a
Apply suggestions from code review
hwwhww Dec 12, 2023
f0af688
Minor fixes
hwwhww Dec 12, 2023
62d1a8f
Add public method markers
dankrad Dec 4, 2023
246477a
SAMPLE -> CELL and cleanups
dankrad Dec 23, 2023
3169f92
More sample -> cell renaming
dankrad Dec 23, 2023
d36fc4f
Zero polynomial -> vanishing polynomial
dankrad Dec 23, 2023
9ec5dde
Remove polynomial_coeff_to_eval
dankrad Dec 23, 2023
c58c4a7
Merge branch 'dev' into polynomial-commitments-sampling
hwwhww Jan 5, 2024
75b1bf5
Add `KZG_SETUP_G1_MONOMIAL` to trusted setup files
hwwhww Jan 5, 2024
5854c7e
Fix some lint errors
hwwhww Jan 5, 2024
7f8858b
Add `PeerDAS` feature
hwwhww Jan 5, 2024
03583b1
Fix fft helper and add basic test
hwwhww Jan 5, 2024
119e00b
Add PeerDAS testing CI job
hwwhww Jan 5, 2024
8fa4ed5
Add `verify_cell_proof_batch` test
hwwhww Jan 5, 2024
9a07270
Rename `recover_cells` to `recover_polynomial` and fix function signa…
hwwhww Jan 8, 2024
db89e29
Clean up Deneb specs. Add some type casting for using fft function
hwwhww Jan 8, 2024
09c2519
Skip pylint check in CI
hwwhww Jan 8, 2024
a58c868
Randomize the test_recover_polynomial()
asn-d6 Jan 9, 2024
5a551a0
Work on hww's round-trip FFT test
asn-d6 Jan 9, 2024
9134cd1
Fix linter
asn-d6 Jan 9, 2024
d21d99f
Add constant for multi cell verification challenge
dankrad Jan 10, 2024
fddbd6b
Remove constants in favour of using compute_roots_of_unity
dankrad Jan 11, 2024
b55ab46
Correct type info for verify_kzg_proof_multi_impl
dankrad Jan 11, 2024
c2522ac
Correct type definition for PolynomialCoeff
dankrad Jan 11, 2024
7ec0a25
Doctoc
dankrad Jan 11, 2024
9a851d9
Linter
dankrad Jan 11, 2024
4cc1e14
Forgot factor of 2 for roots_of_unity_extended
dankrad Jan 12, 2024
b7d9ea9
Rename `peerdas` to `eip7594`
hwwhww Jan 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ jobs:
command: make citest fork=whisk
- store_test_results:
path: tests/core/pyspec/test-reports
test-peerdas:
docker:
- image: circleci/python:3.9
working_directory: ~/specs-repo
steps:
- restore_cache:
key: v3-specs-repo-{{ .Branch }}-{{ .Revision }}
- restore_pyspec_cached_venv
- run:
name: Run py-tests
command: make citest fork=peerdas
- store_test_results:
path: tests/core/pyspec/test-reports
table_of_contents:
docker:
- image: circleci/node:10.16.3
Expand Down Expand Up @@ -323,6 +336,9 @@ workflows:
- test-whisk:
requires:
- install_pyspec_test
- test-peerdas:
requires:
- install_pyspec_test
- table_of_contents
- codespell
- lint:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
needs: [preclear,lint,codespell,table_of_contents]
strategy:
matrix:
version: ["phase0", "altair", "bellatrix", "capella", "deneb", "eip6110", "eip7002", "whisk"]
version: ["phase0", "altair", "bellatrix", "capella", "deneb", "eip6110", "eip7002", "whisk", "peerdas"]
steps:
- name: Checkout this repo
uses: actions/checkout@v3.2.0
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tests/core/pyspec/eth2spec/deneb/
tests/core/pyspec/eth2spec/eip6110/
tests/core/pyspec/eth2spec/eip7002/
tests/core/pyspec/eth2spec/whisk/
tests/core/pyspec/eth2spec/peerdas/

# coverage reports
.htmlcov
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ MARKDOWN_FILES = $(wildcard $(SPEC_DIR)/*/*.md) \
$(wildcard $(SPEC_DIR)/_features/*/*/*.md) \
$(wildcard $(SSZ_DIR)/*.md)

ALL_EXECUTABLE_SPEC_NAMES = phase0 altair bellatrix capella deneb eip6110 eip7002 whisk
ALL_EXECUTABLE_SPEC_NAMES = phase0 altair bellatrix capella deneb eip6110 eip7002 whisk peerdas
# The parameters for commands. Use `foreach` to avoid listing specs again.
COVERAGE_SCOPE := $(foreach S,$(ALL_EXECUTABLE_SPEC_NAMES), --cov=eth2spec.$S.$(TEST_PRESET_TYPE))
PYLINT_SCOPE := $(foreach S,$(ALL_EXECUTABLE_SPEC_NAMES), ./eth2spec/$S)
Expand Down
4 changes: 4 additions & 0 deletions configs/mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,7 @@ BLOB_SIDECAR_SUBNET_COUNT: 6
WHISK_EPOCHS_PER_SHUFFLING_PHASE: 256
# `Epoch(2)`
WHISK_PROPOSER_SELECTION_GAP: 2

# PEERDAS
PEERDAS_FORK_VERSION: 0x06000001
PEERDAS_FORK_EPOCH: 18446744073709551615
4 changes: 4 additions & 0 deletions configs/minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,7 @@ BLOB_SIDECAR_SUBNET_COUNT: 6
# Whisk
WHISK_EPOCHS_PER_SHUFFLING_PHASE: 4
WHISK_PROPOSER_SELECTION_GAP: 1

# PEERDAS
PEERDAS_FORK_VERSION: 0x06000001
PEERDAS_FORK_EPOCH: 18446744073709551615
6 changes: 6 additions & 0 deletions presets/mainnet/peerdas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Mainnet preset - PeerDAS

# Misc
# ---------------------------------------------------------------
# `uint64(2**6)` (= 64)
FIELD_ELEMENTS_PER_CELL: 64
12,418 changes: 8,258 additions & 4,160 deletions presets/mainnet/trusted_setups/trusted_setup_4096.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions presets/minimal/peerdas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Minimal preset - PeerDAS

# Misc
# ---------------------------------------------------------------
# `uint64(2**6)` (= 64)
FIELD_ELEMENTS_PER_CELL: 64
12,418 changes: 8,258 additions & 4,160 deletions presets/minimal/trusted_setups/trusted_setup_4096.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pysetup/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
EIP6110 = 'eip6110'
EIP7002 = 'eip7002'
WHISK = 'whisk'
PEERDAS = 'peerdas'



Expand Down
2 changes: 2 additions & 0 deletions pysetup/md_doc_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
EIP6110,
WHISK,
EIP7002,
PEERDAS,
)


Expand All @@ -21,6 +22,7 @@
EIP6110: DENEB,
WHISK: CAPELLA,
EIP7002: CAPELLA,
PEERDAS: DENEB,
}

ALL_FORKS = list(PREVIOUS_FORK_OF.keys())
Expand Down
3 changes: 2 additions & 1 deletion pysetup/spec_builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
from .eip6110 import EIP6110SpecBuilder
from .eip7002 import EIP7002SpecBuilder
from .whisk import WhiskSpecBuilder
from .peerdas import PeerDASSpecBuilder


spec_builders = {
builder.fork: builder
for builder in (
Phase0SpecBuilder, AltairSpecBuilder, BellatrixSpecBuilder, CapellaSpecBuilder, DenebSpecBuilder,
EIP6110SpecBuilder, EIP7002SpecBuilder, WhiskSpecBuilder,
EIP6110SpecBuilder, EIP7002SpecBuilder, WhiskSpecBuilder, PeerDASSpecBuilder,
)
}
20 changes: 20 additions & 0 deletions pysetup/spec_builders/peerdas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Dict

from .base import BaseSpecBuilder
from ..constants import PEERDAS


class PeerDASSpecBuilder(BaseSpecBuilder):
fork: str = PEERDAS

@classmethod
def imports(cls, preset_name: str):
return f'''
from eth2spec.deneb import {preset_name} as deneb
'''

@classmethod
def hardcoded_custom_type_dep_constants(cls, spec_object) -> Dict[str, str]:
return {
'FIELD_ELEMENTS_PER_CELL': spec_object.preset_vars['FIELD_ELEMENTS_PER_CELL'].value,
}
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ def _load_kzg_trusted_setups(preset_name):

with open(trusted_setups_file_path, 'r') as f:
json_data = json.load(f)
trusted_setup_G1_monomial = json_data['g1_monomial']
trusted_setup_G1_lagrange = json_data['g1_lagrange']
trusted_setup_G2_monomial = json_data['g2_monomial']

return trusted_setup_G2_monomial, trusted_setup_G1_lagrange
return trusted_setup_G1_monomial, trusted_setup_G1_lagrange, trusted_setup_G2_monomial

def _load_curdleproofs_crs(preset_name):
"""
Expand Down Expand Up @@ -167,9 +168,10 @@ def _parse_value(name: str, typed_value: str, type_hint: Optional[str] = None) -
def _update_constant_vars_with_kzg_setups(constant_vars, preset_name):
comment = "noqa: E501"
kzg_setups = ALL_KZG_SETUPS[preset_name]
constant_vars['KZG_SETUP_G2_MONOMIAL'] = VariableDefinition(constant_vars['KZG_SETUP_G2_MONOMIAL'].value, str(kzg_setups[0]), comment, None)
constant_vars['KZG_SETUP_G1_MONOMIAL'] = VariableDefinition(constant_vars['KZG_SETUP_G1_MONOMIAL'].value, str(kzg_setups[0]), comment, None)
constant_vars['KZG_SETUP_G1_LAGRANGE'] = VariableDefinition(constant_vars['KZG_SETUP_G1_LAGRANGE'].value, str(kzg_setups[1]), comment, None)

constant_vars['KZG_SETUP_G2_MONOMIAL'] = VariableDefinition(constant_vars['KZG_SETUP_G2_MONOMIAL'].value, str(kzg_setups[2]), comment, None)


def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str], preset_name=str) -> SpecObject:
functions: Dict[str, str] = {}
Expand Down
125 changes: 125 additions & 0 deletions specs/_features/peerdas/fork.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# PeerDAS -- Fork Logic

**Notice**: This document is a work-in-progress for researchers and implementers.

## Table of contents

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Introduction](#introduction)
- [Configuration](#configuration)
- [Helper functions](#helper-functions)
- [Misc](#misc)
- [Modified `compute_fork_version`](#modified-compute_fork_version)
- [Fork to PeerDAS](#fork-to-peerdas)
- [Fork trigger](#fork-trigger)
- [Upgrading the state](#upgrading-the-state)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Introduction

This document describes the process of PeerDAS upgrade.

## Configuration

Warning: this configuration is not definitive.

| Name | Value |
| - | - |
| `PEERDAS_FORK_VERSION` | `Version('0x05000000')` |
| `PEERDAS_FORK_EPOCH` | `Epoch(18446744073709551615)` **TBD** |

## Helper functions

### Misc

#### Modified `compute_fork_version`

```python
def compute_fork_version(epoch: Epoch) -> Version:
"""
Return the fork version at the given ``epoch``.
"""
if epoch >= PEERDAS_FORK_EPOCH:
return PEERDAS_FORK_VERSION
if epoch >= DENEB_FORK_EPOCH:
return DENEB_FORK_VERSION
if epoch >= CAPELLA_FORK_EPOCH:
return CAPELLA_FORK_VERSION
if epoch >= BELLATRIX_FORK_EPOCH:
return BELLATRIX_FORK_VERSION
if epoch >= ALTAIR_FORK_EPOCH:
return ALTAIR_FORK_VERSION
return GENESIS_FORK_VERSION
```

## Fork to PeerDAS

### Fork trigger

PeerDAS does not need a hard fork. We only add this fork doc for compiling this new feature in pyspec.

For now, we assume the condition will be triggered at epoch `PEERDAS_FORK_EPOCH`.

Note that for the pure PeerDAS networks, we don't apply `upgrade_to_peerdas` since it starts with PeerDAS version logic.

### Upgrading the state

If `state.slot % SLOTS_PER_EPOCH == 0` and `compute_epoch_at_slot(state.slot) == PEERDAS_FORK_EPOCH`,
an irregular state change is made to upgrade to PeerDAS.

```python
def upgrade_to_peerdas(pre: deneb.BeaconState) -> BeaconState:
epoch = deneb.get_current_epoch(pre)
post = BeaconState(
# Versioning
genesis_time=pre.genesis_time,
genesis_validators_root=pre.genesis_validators_root,
slot=pre.slot,
fork=Fork(
previous_version=pre.fork.current_version,
current_version=PEERDAS_FORK_VERSION, # [Modified in PeerDAS]
epoch=epoch,
),
# History
latest_block_header=pre.latest_block_header,
block_roots=pre.block_roots,
state_roots=pre.state_roots,
historical_roots=pre.historical_roots,
# Eth1
eth1_data=pre.eth1_data,
eth1_data_votes=pre.eth1_data_votes,
eth1_deposit_index=pre.eth1_deposit_index,
# Registry
validators=pre.validators,
balances=pre.balances,
# Randomness
randao_mixes=pre.randao_mixes,
# Slashings
slashings=pre.slashings,
# Participation
previous_epoch_participation=pre.previous_epoch_participation,
current_epoch_participation=pre.current_epoch_participation,
# Finality
justification_bits=pre.justification_bits,
previous_justified_checkpoint=pre.previous_justified_checkpoint,
current_justified_checkpoint=pre.current_justified_checkpoint,
finalized_checkpoint=pre.finalized_checkpoint,
# Inactivity
inactivity_scores=pre.inactivity_scores,
# Sync
current_sync_committee=pre.current_sync_committee,
next_sync_committee=pre.next_sync_committee,
# Execution-layer
latest_execution_payload_header=pre.latest_execution_payload_header,
# Withdrawals
next_withdrawal_index=pre.next_withdrawal_index,
next_withdrawal_validator_index=pre.next_withdrawal_validator_index,
# Deep history valid from Capella onwards
historical_summaries=pre.historical_summaries,
)

return post
```