Skip to content

Commit 10b5ed4

Browse files
committed
update docs
1 parent fc5ed1c commit 10b5ed4

File tree

10 files changed

+212
-31
lines changed

10 files changed

+212
-31
lines changed

docs/source/chainio.rst renamed to docs/source/eigensdk.chainio.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _chainio:
1+
.. _eigensdk.chainio:
22

33
eigensdk.chainio
44
================

docs/source/crypto.rst renamed to docs/source/eigensdk.crypto.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _crypto:
1+
.. _eigensdk.crypto:
22

33
eigensdk.crypto
44
===============

docs/source/eigensdk.metrics.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. _eigensdk.metrics:
2+
3+
eigensdk.metrics
4+
================
5+
6+
Metrics

docs/source/nodeapi.rst renamed to docs/source/eigensdk.nodeapi.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _nodeapi:
1+
.. _eigensdk.nodeapi:
22

33
eigensdk.nodeapi
44
================

docs/source/eigensdk.services.rst

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
.. _eigensdk.services:
2+
3+
eigensdk.services
4+
=================
5+
6+
eigensdk.services.operatorsinfo
7+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8+
9+
The ``OperatorsInfoServiceInMemory`` is a service designed to manage and maintain a local in-memory store of operator details such as public keys and network socket information. It periodically updates its data by querying the blockchain through an ``AvsRegistryReader`` instance.
10+
11+
Initialization
12+
--------------
13+
14+
The service is initialized with the following parameters:
15+
16+
- **avs_registry_reader**: An instance of ``AvsRegistryReader`` used to access operator-related data on the blockchain.
17+
- **start_block_pub**: The starting block number for querying registered public keys.
18+
- **start_block_socket**: The starting block number for querying socket information.
19+
- **check_interval**: The interval in seconds between checks for updates.
20+
- **log_filter_query_block_range**: The range of blocks to query in one request.
21+
- **logger**: An optional logger instance for logging events and errors.
22+
23+
.. py:class:: OperatorsInfoServiceInMemory(avs_registry_reader: AvsRegistryReader, start_block_pub: int = 0, start_block_socket: int = 0, check_interval: int = 10, log_filter_query_block_range: int = 10000, logger: Optional[logging.Logger] = None)
24+
25+
Initializes a new instance of the ``OperatorsInfoServiceInMemory``.
26+
27+
:param avs_registry_reader: Instance of ``AvsRegistryReader`` for blockchain queries.
28+
:param start_block_pub: Starting block number for public key queries.
29+
:param start_block_socket: Starting block number for socket info queries.
30+
:param check_interval: Time interval between update checks.
31+
:param log_filter_query_block_range: Block range for each query to the blockchain.
32+
:param logger: Logger for event logging.
33+
34+
Functionality
35+
-------------
36+
37+
The service runs continuously in a separate thread, periodically updating its internal data stores based on the latest information from the blockchain. It supports the following functionalities:
38+
39+
- **Operator Public Key Retrieval**: Fetches and stores the latest public keys registered on the blockchain.
40+
- **Operator Socket Information Retrieval**: Fetches and stores the latest socket information registered on the blockchain.
41+
- **Operator Info Retrieval**: Provides a method to retrieve detailed information about an operator given their address.
42+
43+
.. py:method:: get_operator_info(operator_addr: Address) -> OperatorInfo
44+
45+
Retrieves detailed information about an operator, including their socket information and public keys.
46+
47+
:param operator_addr: The blockchain address of the operator.
48+
:return: An instance of ``OperatorInfo`` containing the operator's details.
49+
50+
Example Usage
51+
-------------
52+
53+
The service can be used in an application that requires up-to-date information about blockchain operators, such as in a decentralized application (dApp) that interacts with various blockchain services:
54+
55+
.. code-block:: python
56+
57+
>>> operator_info_service = OperatorsInfoServiceInMemory(clients.avs_registry_reader)
58+
>>> operator_info = operator_info_service.get_operator_info('0x123...')
59+
>>> print(f"Operator Socket: {operator_info.socket}, Public Keys: {operator_info.pub_keys}")
60+
61+
62+
This example initializes the service and retrieves operator information, demonstrating how to integrate and utilize the ``OperatorsInfoServiceInMemory`` within larger systems.
63+
64+
eigensdk.services.avsregistry
65+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66+
67+
The ``AvsRegistryService`` is designed to aggregate and provide access to detailed state information about operators and their stakes across different quorums. It utilizes data from both the ``AvsRegistryReader`` and ``OperatorsInfoServiceInMemory`` to construct comprehensive views of the AVS (Autonomous Validation Services) landscape at specific blockchain states.
68+
69+
Initialization
70+
--------------
71+
72+
The service is initialized with instances of ``AvsRegistryReader`` and ``OperatorsInfoServiceInMemory``, along with a logger for event logging.
73+
74+
.. py:class:: AvsRegistryService(avs_registry_reader: AvsRegistryReader, operator_info_service: OperatorsInfoServiceInMemory, logger: logging.Logger)
75+
76+
Initializes a new instance of the ``AvsRegistryService``.
77+
78+
:param avs_registry_reader: Instance of ``AvsRegistryReader`` for reading blockchain data.
79+
:param operator_info_service: Instance of ``OperatorsInfoServiceInMemory`` for managing in-memory operator data.
80+
:param logger: Logger for event logging.
81+
82+
Functionality
83+
-------------
84+
85+
The service offers functionalities to retrieve aggregated operator states and quorum states at specific blocks, helping in the analysis and management of AVS.
86+
87+
.. py:method:: get_operators_avs_state_at_block(quorum_numbers: List[int], block_number: int) -> Dict[bytes, OperatorAvsState]
88+
89+
Retrieves the AVS state of operators at a specific blockchain block.
90+
91+
:param quorum_numbers: List of quorum numbers to query.
92+
:param block_number: The blockchain block number at which to get the state.
93+
:return: A dictionary mapping operator IDs to their ``OperatorAvsState``.
94+
95+
.. py:method:: get_quorums_avs_state_at_block(quorum_numbers: List[int], block_number: int) -> Dict[int, Dict[str, Union[int, G1Point]]]
96+
97+
Aggregates the state of specified quorums at a given block number, including the aggregated public keys and total stakes.
98+
99+
:param quorum_numbers: List of quorum numbers to aggregate.
100+
:param block_number: The blockchain block number at which to aggregate the state.
101+
:return: A dictionary with quorum numbers as keys and details including aggregated public keys, total stakes, and block numbers.
102+
103+
Example Usage
104+
-------------
105+
106+
The following example demonstrates how to use the ``AvsRegistryService`` to fetch and display operator and quorum states at a specific blockchain block:
107+
108+
.. code-block:: python
109+
110+
>>> avs_registry_service = AvsRegistryService(clients.avs_registry_reader, operator_info_service, logger)
111+
>>> quorum_numbers = [0, 1]
112+
>>> block_number = 12345
113+
>>> operators_state = avs_registry_service.get_operators_avs_state_at_block(quorum_numbers, block_number)
114+
>>> print(operators_state)
115+
>>> quorums_state = avs_registry_service.get_quorums_avs_state_at_block(quorum_numbers, block_number)
116+
>>> print(quorums_state)
117+
118+
This example shows how to initialize the service and retrieve detailed state information for operators and quorums, providing insights into the current and historical configurations of the AVS within the blockchain.
119+
120+
121+
eigensdk.services.bls_aggregation.blsagg
122+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123+
124+
The ``BlsAggregationService`` is integral to aggregating Boneh-Lynn-Shacham (BLS) signatures in distributed validation systems, ensuring task authenticity and integrity across multiple nodes.
125+
126+
Initialization
127+
--------------
128+
129+
The service is initiated with an instance of ``AvsRegistryService`` and a cryptographic hash function. These components enable it to verify and aggregate signatures while interacting with blockchain state data.
130+
131+
.. py:class:: BlsAggregationService(avs_registry_service: AvsRegistryService, hash_function: any)
132+
133+
Initializes a new instance of ``BlsAggregationService``.
134+
135+
:param avs_registry_service: An instance of ``AvsRegistryService`` used for querying blockchain data.
136+
:param hash_function: A cryptographic hash function used for digest generation.
137+
138+
Functionality
139+
-------------
140+
141+
The service provides methods to initialize new tasks, process new signatures, and retrieve aggregated responses. It verifies signatures against blockchain data and aggregates them if they meet predefined quorum requirements.
142+
143+
.. py:method:: initialize_new_task(task_index: int, task_created_block: int, quorum_numbers: List[int], quorum_threshold_percentages: List[int], time_to_expiry: int)
144+
145+
Prepares a new task for aggregation, setting initial parameters and storing them internally.
146+
147+
.. py:method:: process_new_signature(task_index: int, task_response: str, bls_signature: Signature, operator_id: int)
148+
149+
Processes and aggregates a new BLS signature related to a specific task, verifying its authenticity and adding it to the aggregate.
150+
151+
.. py:method:: get_aggregated_responses() -> Iterator[BlsAggregationServiceResponse]
152+
153+
Yields completed task responses once they meet aggregation criteria, indicating successful validation.
154+
155+
Data Structures
156+
---------------
157+
158+
- **TaskListItem**: Maintains task-specific data, including state of operator signatures and stake thresholds.
159+
- **AggregatedOperators**: Stores aggregated public keys and signatures for operators who have signed a specific task response.
160+
161+
Example Usage
162+
-------------
163+
164+
The following example demonstrates initializing the service, managing task signatures, and validating task completion:
165+
166+
.. code-block:: python
167+
168+
>>> bls_aggregation_service = BlsAggregationService(avs_registry_service, hash_function)
169+
>>> task_index = 1
170+
>>> quorum_numbers = [0, 1]
171+
>>> quorum_thresholds = [70, 70]
172+
>>> # Initialize a new task
173+
>>> bls_aggregation_service.initialize_new_task(task_index, 123456, quorum_numbers, quorum_thresholds, 3600)
174+
>>> # Process a new signature
175+
>>> operator_id = 101
176+
>>> task_response = 'response data'
177+
>>> bls_signature = Signature(...) # Assuming a valid BLS signature
178+
>>> bls_aggregation_service.process_new_signature(task_index, task_response, bls_signature, operator_id)
179+
>>> # Retrieve and handle aggregated responses
180+
>>> for response in bls_aggregation_service.get_aggregated_responses():
181+
... print(response)
182+
183+
This service is crucial for ensuring tasks are validated correctly and efficiently, using cryptographic guarantees provided by BLS signatures and blockchain data.
184+

docs/source/index.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ EigenSDK Python Documentation
55

66
It enables BLS `signing <https://eth2book.info/capella/part2/building_blocks/signatures/>`_ and `aggregation <https://eth2book.info/capella/part2/building_blocks/signatures/#aggregation>`_, while also providing a wrapper for interacting with both EigenLayer's `core contracts <https://github.com/Layr-Labs/eigenlayer-contracts>`_ and `AVS-specific contracts <https://github.com/Layr-Labs/eigenlayer-middleware/>`_. Additionally, the SDK includes implementations of `NodeAPI <https://docs.eigenlayer.xyz/category/avs-node-api>`_ and `Metrics API <https://docs.eigenlayer.xyz/category/metrics>`_, offering essential tools for effective monitoring and management of AVS operations, ensuring a cohesive development environment within the EigenLayer ecosystem.
77

8+
Getting Started
9+
~~~~~~~~~~~~~~~
10+
811
.. warning::
912

1013
This library is a PoC implemented for the EigenLayer hackathon. Do not use it in Production, testnet only.
1114

15+
- Ready to code? → :ref:`quickstart`
16+
- Example AVS using this SDK? → `Incredible Squaring AVS <https://github.com/zellular-xyz/incredible-squaring-avs-python>`_
17+
- Read the source? → `Github <https://github.com/zellular-xyz/eigensdk-python>`_
18+
1219
Table of Contents
1320
-----------------
1421

@@ -22,8 +29,8 @@ Table of Contents
2229
:maxdepth: 1
2330
:caption: API
2431

25-
chainio
26-
crypto
27-
services
28-
nodeapi
29-
metrics
32+
eigensdk.chainio
33+
eigensdk.crypto
34+
eigensdk.services
35+
eigensdk.nodeapi
36+
eigensdk.metrics

docs/source/metrics.rst

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/source/services.rst

Lines changed: 0 additions & 6 deletions
This file was deleted.

eigensdk/services/bls_aggregation/__init__.py

Whitespace-only changes.

eigensdk/services/bls_aggregation/blsagg.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def is_json_serializable(obj):
2424

2525
@dataclass
2626
class BlsAggregationServiceResponse:
27-
err: Exception = None # if err is not None, the other fields are not valid
2827
task_index: int = None # unique identifier of the task
2928
task_response: any = None # the task response that was signed
3029
task_response_digest: any = None # digest of the task response that was signed
@@ -115,7 +114,7 @@ def initialize_new_task(
115114
quorum_numbers: list[int],
116115
quorum_threshold_percentages: list[int],
117116
time_to_expiry: int,
118-
) -> Exception: ...
117+
): ...
119118

120119
# ProcessNewSignature processes a new signature over a taskResponseDigest for a particular taskIndex by a particular operator
121120
# It verifies that the signature is correct and returns an error if it is not, and then aggregates the signature and stake of
@@ -128,7 +127,7 @@ def process_new_signature(
128127
taskResponse: any,
129128
blsSignature: Signature,
130129
operatorId: int,
131-
) -> Exception: ...
130+
): ...
132131

133132
# GetResponseChannel returns the single channel that meant to be used as the response channel
134133
# Any task that is completed (see the completion criterion in the comment above InitializeNewTask)
@@ -177,7 +176,7 @@ def initialize_new_task(
177176
quorum_numbers: list[int],
178177
quorum_threshold_percentages: list[int],
179178
time_to_expiry: int,
180-
) -> Exception:
179+
):
181180
if task_index in self.responses:
182181
raise ValueError("Task alredy initialized")
183182

@@ -319,7 +318,6 @@ def process_new_signature(
319318
)
320319

321320
result = BlsAggregationServiceResponse(
322-
err=None,
323321
task_index=task_index,
324322
task_response=task_response,
325323
task_response_digest=task_response_digest,
@@ -368,11 +366,11 @@ def __verify_signature(
368366
task_index: int,
369367
signed_task_response_digest: SignedTaskResponseDigest,
370368
operators_avs_state_dict: dict[int, OperatorAvsState],
371-
) -> Exception:
369+
):
372370
operator_id = signed_task_response_digest.operator_id
373371

374372
if operator_id not in operators_avs_state_dict:
375-
return ValueError(f"Operator {operator_id} is not part of task quorum")
373+
raise ValueError(f"Operator {operator_id} is not part of task quorum")
376374

377375
task_response_digest = self.hash_function(
378376
signed_task_response_digest.task_response
@@ -382,13 +380,11 @@ def __verify_signature(
382380
operator_id
383381
].operator_info.pub_keys.g2_pub_key
384382
if not operator_g2_pub_key:
385-
return ValueError(
383+
raise ValueError(
386384
f"TaskId: {task_index} operator G2 PubKey not fount for operator {operator_id}"
387385
)
388386

389387
signature = signed_task_response_digest.bls_signature
390388
verified = signature.verify(operator_g2_pub_key, task_response_digest)
391389
if not verified:
392-
return ValueError("Incorrect signature error")
393-
394-
return None
390+
raise ValueError("Incorrect signature error")

0 commit comments

Comments
 (0)