Incredible Squaring AVS Example
Introduction
This guide will walk you through building an EigenLayer AVS (Actively Validated Service) using Tangle Blueprints, using examples from the Incredible Squaring blueprint implementation.
The Incredible Squaring AVS is a simple example that demonstrates how to build an AVS that squares numbers. While the computation is trivial, the example showcases the key components of an EigenLayer AVS built with Tangle Blueprints.
Blueprint Structure
The Incredible Squaring AVS blueprint follows the basic library and binary structure:
- Library: Contains job definitions and core logic
- Binary: Contains the Blueprint Runner implementation
Job Definitions
Jobs are the core computational units in your Blueprint. For the Incredible Squaring AVS, we define jobs to handle various tasks:
This job initializes a new task in the Incredible Squaring AVS. It takes parameters from an EVM event and processes them.
This job computes the square of a number in the Incredible Squaring AVS and sends the result as a signed response to an Aggregator.
Working with EVM Smart Contracts
To interact with EVM smart contracts, the blueprint uses the alloy
crate
Blueprint Runner Architecture
The Blueprint Runner is the core component that orchestrates the execution of your Blueprint. For the Incredible Squaring AVS, it consists of several key components:
1. Setting Up the Provider
First, create an HTTP provider to connect to the Ethereum network with a wallet enabled for transacting:
2. Creating Contexts
Next, create the contexts that will be used by your jobs:
3. Setting Up Producers
Producers listen for events and prepare them for processing. In the Incredible Squaring AVS, we set up producers to listen for EVM events:
4. Configuring the Blueprint Runner
Finally, set up the Blueprint Runner with the router, producers, consumers, and background services:
The Blueprint Runner:
- Uses a router to direct job calls to the appropriate handlers
- Sets up a producer that listen for events and prepare them for processing
- Our job automatically handles signed task responses, so we don’t use a consumer
- Configures Aggregator as background services
Testing the Incredible Squaring AVS
1. Prerequisites
Before you begin, ensure you have the following installed:
- Anvil
- Docker (DockerDesktop)
2. Installation
Clone this repository:
git clone https://github.com/tangle-network/blueprint.git
cd blueprint
Install Anvil:
curl -L https://foundry.paradigm.xyz | bash
foundryup
3. Running the AVS on a Testnet
We have a test for running this AVS Blueprint on a local Anvil Testnet. You can run the test with the following:
cargo test --package incredible-squaring-blueprint-eigenlayer test_eigenlayer_incredible_squaring_blueprint
Best Practices and Considerations
- Error Handling: Implement robust error handling in your job functions to manage potential failures gracefully.
- Asynchronous Operations: Use
async/await
for operations that may take time, such as network requests or complex computations. - State Management: If your AVS needs to maintain state between job executions, consider implementing a state management system.
- Testing: Implement unit tests for your job logic and integration tests for the complete AVS.
- Logging: Use appropriate logging to track the job execution process and aid in debugging.
- Gas Considerations: Be aware of the gas costs associated with your on-chain interactions, especially when responding to events with transactions.
- Scalability: Design your AVS to scale with the number of tasks you expect to process.
- Security: Ensure your AVS follows security best practices, especially when handling cryptographic operations.