Skip to content

Commit

Permalink
Merge branch 'staging' into refactor-user-states
Browse files Browse the repository at this point in the history
  • Loading branch information
entropidelic committed Oct 2, 2024
2 parents f6febd9 + ba808d2 commit fc5e488
Show file tree
Hide file tree
Showing 65 changed files with 1,727 additions and 1,406 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build-rust-projects
name: build-and-test-rust-projects

on:
merge_group:
Expand All @@ -7,13 +7,13 @@ on:
pull_request:
branches: ["*"]
paths:
- 'batcher/**'
- '.github/workflows/build-rust.yml'
- "batcher/**"
- ".github/workflows/build-rust.yml"

jobs:
build:
runs-on: aligned-runner

steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -45,3 +45,24 @@ jobs:
run: |
cd batcher
cargo build --all
test:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache Rust dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
batcher/target
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-rust-
- name: Run tests
run: |
cd batcher
cargo test --all
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ update_operator:
@make build_operator
@./operator/build/aligned-operator --version

operator_valid_marshall_fuzz_macos:
@cd operator/pkg && go test -fuzz=FuzzValidMarshall -ldflags=-extldflags=-Wl,-ld_classic

operator_valid_marshall_fuzz_linux:
@cd operator/pkg && \
LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):$(CURDIR)/operator/risc_zero/lib \
go test -fuzz=FuzzValidMarshall

operator_marshall_unmarshall_fuzz_macos:
@cd operator/pkg && go test -fuzz=FuzzMarshalUnmarshal -ldflags=-extldflags=-Wl,-ld_classic

operator_marshall_unmarshall_fuzz_linux:
@cd operator/pkg && \
LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):$(CURDIR)/operator/risc_zero/lib \
go test -fuzz=FuzzMarshalUnmarshal

bindings:
cd contracts && ./generate-go-bindings.sh

Expand Down
188 changes: 1 addition & 187 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,190 +3,4 @@
> [!CAUTION]
> To be used in testnet only.
## Table of Contents

- [Aligned](#aligned)
- [Table of Contents](#table-of-contents)
- [The Project](#the-project)
- [How to use the testnet](#how-to-use-the-testnet)
- [Operator Guide](#operator-guide)
- [Aligned Infrastructure Guide](#aligned-infrastructure-guide)
- [Submitting Proofs to Aligned](#submitting-proofs-to-aligned)
- [Integrating Aligned into your Project](#integrating-aligned-into-your-project)
- [Versioning and Networks](#versioning-and-networks)


## The Project

Aligned is a decentralized network of nodes that verifies Zero-Knowledge and Validity proofs, and post the results in Ethereum.

These proofs can be generated and used for a tenth of the price, and with extremely low latency, allowing novel types of applications that weren't possible before in Ethereum.

## How to use the testnet

1. Download and install Aligned to send proofs in the testnet:

```bash
curl -L https://raw.githubusercontent.com/yetanotherco/aligned_layer/main/batcher/aligned/install_aligned.sh | bash
```

2. Then run the ```source``` command that should appear in the shell.


3. Download an example SP1 proof file with it's ELF file using:

```bash
curl -L https://raw.githubusercontent.com/yetanotherco/aligned_layer/main/batcher/aligned/get_proof_test_files.sh | bash
```

We are downloading a proof previously generated, sending it to Aligned, and retrieving the results from Ethereum Holesky testnet. Aligned is using EigenLayer to do a fast and cheap verification of more than one thousand proofs per second.

4. Let's send the proof to be verified in Aligned:

```bash
rm -rf ~/.aligned/aligned_verification_data/ &&
aligned submit \
--proving_system SP1 \
--proof ~/.aligned/test_files/sp1_fibonacci.proof \
--vm_program ~/.aligned/test_files/sp1_fibonacci.elf \
--aligned_verification_data_path ~/.aligned/aligned_verification_data \
--batcher_url wss://batcher.alignedlayer.com \
--rpc_url https://ethereum-holesky-rpc.publicnode.com \
--payment_service_addr 0x815aeCA64a974297942D2Bbf034ABEe22a38A003
```

5. You should get a response like this:

```bash
[2024-07-01T19:17:54Z WARN aligned] Missing keystore used for payment. This proof will not be included if sent to Eth Mainnet
[2024-07-01T19:17:54Z INFO aligned] Submitting proofs to the Aligned batcher...
[2024-07-01T19:19:18Z INFO aligned] Batch inclusion data written into ./aligned_verification_data/e367d76e_0.json
[2024-07-01T19:19:18Z INFO aligned] Proofs submitted to aligned. See the batch in the explorer:
[2024-07-01T19:19:18Z INFO aligned] https://explorer.alignedlayer.com/batches/0xe367d76e832edec893d3a9027b3c231b2e3994c47acfac2e67197c13c9be0c4c
```
You can use the link to the explorer to check the status of your transaction.
6. After three Ethereum blocks, you can check if it has been verified with:
```bash
aligned verify-proof-onchain \
--aligned-verification-data ~/.aligned/aligned_verification_data/*.json \
--rpc_url https://ethereum-holesky-rpc.publicnode.com \
--chain holesky \
--payment_service_addr 0x815aeCA64a974297942D2Bbf034ABEe22a38A003
```
This is reading the result of the verification of the proof in Ethereum.
7. You should get this result:
```bash
[2024-06-17T21:58:43Z INFO aligned] Your proof was verified in Aligned and included in the batch!
```
If the proof wasn't verified you should get this result:
```bash
[2024-06-17T21:59:09Z INFO aligned] Your proof was not included in the batch.
```
Aligned works in:
- MacOS Arm64 (M1 or higher)
- Linux x86 with GLIBC_2.32 or superior (For example, Ubuntu 22.04 or higher)
If you don't meet these requirements, clone the repository, install rust, and then run:
```bash
make uninstall_aligned
make install_aligned_compiling
```
### Reading the results of proof verification in Ethereum
#### Using CURL and an Ethereum RPC
In step 6 of the previous section, we used the `aligned verify-proof-onchain` to check that our proof was verified in Aligned.
Internally, this is making a call to our Aligned contract, verifying commitments are right, and that the proof is included in the batch.
That command is doing the same as the following `curl` to an Ethereum node.
```bash
curl -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_call","id":1, "params":[{"to": "0x58F280BeBE9B34c9939C3C39e0890C81f163B623", "data": "<CALL_DATA>"}]}' \
-X POST https://ethereum-holesky-rpc.publicnode.com
```
This will return 0x1 if the proof and it's associated data is correct and verified in Aligned, and 0x0 if not.
For example, this a correct calldata for a verified proof:
```bash
curl -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_call","id":1,"params":[{"to": "0x58F280BeBE9B34c9939C3C39e0890C81f163B623", "data": "0xfa534dc0c181e470901eecf693bfa6f0e89e837dcf35700cdd91c210a0ce0660e86742080000000000000000000000000000000000000000000000000000000000000000836371a502bf5ad67be837b21fa99bc381f7e8124f02042ffb80fa7ce27bc8f6f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000007553cb14bff387c06e016cb3e7946e91d9fe44a54ad5d888ce8343ddb16116a700000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000007600000000000000000000000000000000000000000000000000000000000001007b2f4966c3ab3e59d213eda057734df28c323055a2a02f50bd286585cc80128c967250f2b9ad990485338fd2d49e83f47917983f5566da551d4c32e9063ea5641d94b04bac222e06ea18cbb617d0d52c7007cc8f8b30c435b8b8101bdff0ea8482436acf251652f00397f4cefa0bb8eea1c8addb6cf2ca843004b89d80c7e1e41344fd2387535fe4afcaafde27b04543d993bbbc7286154044913e5bd65b86d7cc4d47a90132a95d9ffecb913b414ba2d2f0b1d7b826eb5025a27bcadcc0d94cb125c9c9d556eac08dd6b0f5f55f68afe699f3c529442dbf1b47e968b3705ee2e1be4acb884d184a139a390cb94e9e5806686605dc0a025269bc3afd990c8302"}]}' \
-X POST https://ethereum-holesky-rpc.publicnode.com
```
To generate the calldata yourself, follow these steps:
1. Clone the repository and move into it.
2. Create a Python virtual environment and install the dependencies with:
```bash
python3 -m venv .aligned_venv
source .aligned_venv/bin/activate
python3 -m pip install -r examples/verify/requirements.txt
```
3. Encode your proof verification data with:
```bash
python3 examples/verify/encode_verification_data.py --aligned-verification-data ~/.aligned/aligned_verification_data/*.json
```
If your verification data is in another path, just change the `--aligned-verification-data` parameter.
#### Using a caller contract
To verify a proof in your own contract, use a static call to the Aligned contract. You can use the following [Caller Contract](examples/verify/src/VerifyBatchInclusionCaller.sol) as an example. The code will look like this:
```solidity
(bool callWasSuccessfull, bytes memory proofIsIncluded) = targetContract.staticcall(
abi.encodeWithSignature(
"verifyBatchInclusion(bytes32,bytes32,bytes32,bytes20,bytes32,bytes,uint256)",
proofCommitment,
pubInputCommitment,
provingSystemAuxDataCommitment,
proofGeneratorAddr,
batchMerkleRoot,
merkleProof,
verificationDataBatchIndex
)
);
require(callWasSuccessfull, "static_call failed");
```
## Operator Guide
If you want to run an operator, check our [Operator Guide](./docs/operator_guides/0_running_an_operator.md).
## Aligned Infrastructure Guide
If you are developing on Aligned, or want to run your own devnet, check our [setup Aligned guide](docs/3_guides/6_setup_aligned.md).
## Submitting Proofs to Aligned
For submitting proofs generated by your own project to the network via CLI, see the documentation on [submitting proofs to Aligned](docs/3_guides/0_submitting_proofs.md).
## Integrating Aligned into your Project
If you are developing applications using Aligned, we offer a [Rust-SDK](docs/3_guides/1_SDK_how_to.md) for submitting proofs directly to the network within your applications.
## Versioning and Networks
Testnet code and documentation is always in sync with the default [Testnet Branch](https://github.com/yetanotherco/aligned_layer/tree/feat/testnet)
Releases are provided for each version of the testnet.
Latest version of the code, deployed on staging network, is always on [Staging Branch](https://github.com/yetanotherco/aligned_layer/tree/feat/staging)
To learn more about Aligned and how to use it, refer to the [docs page](https://docs.alignedlayer.com/) or [docs folder](./docs/).
20 changes: 1 addition & 19 deletions aggregator/internal/pkg/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ type Aggregator struct {
// Stores the TaskResponse for each batch by batchIdentifierHash
batchDataByIdentifierHash map[[32]byte]BatchData

// Stores if an operator already submitted a response for a batch
// This is to avoid double submissions
// struct{} is used as a placeholder because it is the smallest type
// go does not have a set type
operatorRespondedBatch map[uint32]map[eigentypes.Bytes32]struct{}

// This task index is to communicate with the local BLS
// Service.
// Note: In case of a reboot it can start from 0 again
Expand Down Expand Up @@ -146,7 +140,7 @@ func NewAggregator(aggregatorConfig config.AggregatorConfig) (*Aggregator, error
return taskResponseDigest, nil
}

operatorPubkeysService := oppubkeysserv.NewOperatorsInfoServiceInMemory(context.Background(), clients.AvsRegistryChainSubscriber, clients.AvsRegistryChainReader, nil, logger)
operatorPubkeysService := oppubkeysserv.NewOperatorsInfoServiceInMemory(context.Background(), clients.AvsRegistryChainSubscriber, clients.AvsRegistryChainReader, nil, oppubkeysserv.Opts{}, logger)
avsRegistryService := avsregistry.NewAvsRegistryServiceChainCaller(avsReader.ChainReader, operatorPubkeysService, logger)
blsAggregationService := blsagg.NewBlsAggregatorService(avsRegistryService, hashFunction, logger)

Expand All @@ -167,7 +161,6 @@ func NewAggregator(aggregatorConfig config.AggregatorConfig) (*Aggregator, error
batchesIdxByIdentifierHash: batchesIdxByIdentifierHash,
batchDataByIdentifierHash: batchDataByIdentifierHash,
batchCreatedBlockByIdx: batchCreatedBlockByIdx,
operatorRespondedBatch: make(map[uint32]map[eigentypes.Bytes32]struct{}),
nextBatchIndex: nextBatchIndex,
taskMutex: &sync.Mutex{},
walletMutex: &sync.Mutex{},
Expand Down Expand Up @@ -220,12 +213,6 @@ func (agg *Aggregator) handleBlsAggServiceResponse(blsAggServiceResp blsagg.BlsA
agg.taskMutex.Lock()
batchIdentifierHash := agg.batchesIdentifierHashByIdx[blsAggServiceResp.TaskIndex]
agg.logger.Error("BlsAggregationServiceResponse contains an error", "err", blsAggServiceResp.Err, "batchIdentifierHash", hex.EncodeToString(batchIdentifierHash[:]))
agg.logger.Info("- Locking task mutex: Delete task from operator map", "taskIndex", blsAggServiceResp.TaskIndex)

// Remove task from the list of tasks
delete(agg.operatorRespondedBatch, blsAggServiceResp.TaskIndex)

agg.logger.Info("- Unlocking task mutex: Delete task from operator map", "taskIndex", blsAggServiceResp.TaskIndex)
agg.taskMutex.Unlock()
return
}
Expand Down Expand Up @@ -254,10 +241,6 @@ func (agg *Aggregator) handleBlsAggServiceResponse(blsAggServiceResp blsagg.BlsA
batchIdentifierHash := agg.batchesIdentifierHashByIdx[blsAggServiceResp.TaskIndex]
batchData := agg.batchDataByIdentifierHash[batchIdentifierHash]
taskCreatedBlock := agg.batchCreatedBlockByIdx[blsAggServiceResp.TaskIndex]

// Delete the task from the map
delete(agg.operatorRespondedBatch, blsAggServiceResp.TaskIndex)

agg.AggregatorConfig.BaseConfig.Logger.Info("- Unlocked Resources: Fetching merkle root")
agg.taskMutex.Unlock()

Expand All @@ -282,7 +265,6 @@ func (agg *Aggregator) handleBlsAggServiceResponse(blsAggServiceResp blsagg.BlsA
agg.logger.Info("Aggregator successfully responded to task",
"taskIndex", blsAggServiceResp.TaskIndex,
"batchIdentifierHash", "0x"+hex.EncodeToString(batchIdentifierHash[:]))

return
}

Expand Down
26 changes: 1 addition & 25 deletions aggregator/internal/pkg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"net/rpc"
"time"

eigentypes "github.com/Layr-Labs/eigensdk-go/types"

"github.com/yetanotherco/aligned_layer/core/types"
)

Expand Down Expand Up @@ -74,26 +72,6 @@ func (agg *Aggregator) ProcessOperatorSignedTaskResponseV2(signedTaskResponse *t
return nil
}

// Note: we already have lock here
agg.logger.Debug("- Checking if operator already responded")
batchResponses, ok := agg.operatorRespondedBatch[taskIndex]
if !ok {
batchResponses = make(map[eigentypes.Bytes32]struct{})
agg.operatorRespondedBatch[taskIndex] = batchResponses
}

if _, ok := batchResponses[signedTaskResponse.OperatorId]; ok {
*reply = 0
agg.logger.Warn("Operator already responded, ignoring",
"operatorId", hex.EncodeToString(signedTaskResponse.OperatorId[:]),
"taskIndex", taskIndex, "batchMerkleRoot", hex.EncodeToString(signedTaskResponse.BatchMerkleRoot[:]))

agg.taskMutex.Unlock()
return nil
}

batchResponses[signedTaskResponse.OperatorId] = struct{}{}

// Don't wait infinitely if it can't answer
// Create a context with a timeout of 5 seconds
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
Expand All @@ -111,9 +89,7 @@ func (agg *Aggregator) ProcessOperatorSignedTaskResponseV2(signedTaskResponse *t

if err != nil {
agg.logger.Warnf("BLS aggregation service error: %s", err)
// remove operator from the list of operators that responded
// so that it can try again
delete(batchResponses, signedTaskResponse.OperatorId)
// todo shouldn't we here close the channel with a reply = 1?
} else {
agg.logger.Info("BLS process succeeded")
}
Expand Down
Loading

0 comments on commit fc5e488

Please sign in to comment.