forked from Layr-Labs/incredible-squaring-avs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
79 changed files
with
10,542 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
coverage.html | ||
|
||
# log files | ||
logs.txt | ||
|
||
# just for example | ||
id_rsa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
############################# HELP MESSAGE ############################# | ||
# Make sure the help command stays first, so that it's printed by default when `make` is called without arguments | ||
.PHONY: help tests | ||
help: | ||
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
AGGREGATOR_ECDSA_PRIV_KEY=0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6 | ||
CHALLENGER_ECDSA_PRIV_KEY=0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a | ||
|
||
CHAINID=31337 | ||
# Make sure to update this if the strategy address changes | ||
# check in contracts/script/output/${CHAINID}/credible_squaring_avs_deployment_output.json | ||
STRATEGY_ADDRESS=0x7a2088a1bFc9d81c55368AE168C2C02570cB814F | ||
DEPLOYMENT_FILES_DIR=contracts/script/output/${CHAINID} | ||
|
||
-----------------------------: ## | ||
|
||
___CONTRACTS___: ## | ||
|
||
deploy-eigenlayer-contracts-to-anvil-and-save-state: ## Deploy eigenlayer | ||
./tests/integration/deploy-eigenlayer-save-anvil-state.sh | ||
|
||
deploy-shared-avs-contracts-to-anvil-and-save-state: ## Deploy blspubkeycompendium and blsstateoperatorretriever | ||
./tests/integration/deploy-shared-avs-contracts-save-anvil-state.sh | ||
|
||
deploy-incredible-squaring-contracts-to-anvil-and-save-state: ## Deploy avs | ||
./tests/integration/deploy-avs-save-anvil-state.sh | ||
|
||
deploy-all-to-anvil-and-save-state: deploy-eigenlayer-contracts-to-anvil-and-save-state deploy-shared-avs-contracts-to-anvil-and-save-state deploy-incredible-squaring-contracts-to-anvil-and-save-state ## deploy eigenlayer, shared avs contracts, and inc-sq contracts | ||
|
||
start-anvil-chain-with-el-and-avs-deployed: ## starts anvil from a saved state file (with el and avs contracts deployed) | ||
anvil --load-state tests/integration/avs-and-eigenlayer-deployed-anvil-state.json | ||
|
||
bindings: ## generates contract bindings | ||
cd contracts && ./generate-go-bindings.sh | ||
|
||
___DOCKER___: ## | ||
docker-build-and-publish-images: ## builds and publishes operator and aggregator docker images using Ko | ||
KO_DOCKER_REPO=ghcr.io/layr-labs/incredible-squaring ko build aggregator/cmd/main.go --preserve-import-paths | ||
KO_DOCKER_REPO=ghcr.io/layr-labs/incredible-squaring ko build operator/cmd/main.go --preserve-import-paths | ||
docker-start-everything: docker-build-and-publish-images ## starts aggregator and operator docker containers | ||
docker compose pull && docker compose up | ||
|
||
__CLI__: ## | ||
|
||
cli-setup-operator: send-fund cli-register-operator-with-eigenlayer cli-register-operator-bls-pubkeys cli-deposit-into-mocktoken-strategy cli-register-operator-with-avs ## registers operator with eigenlayer and avs | ||
|
||
cli-register-operator-with-eigenlayer: ## registers operator with delegationManager | ||
go run cli/main.go --config config-files/node_config.anvil.yaml register-operator-with-eigenlayer | ||
|
||
cli-register-operator-bls-pubkeys: ## registers operator's bls public keys with blsPublicKeyCompendium | ||
go run cli/main.go --config config-files/node_config.anvil.yaml register-operator-bls-pubkeys | ||
|
||
cli-deposit-into-mocktoken-strategy: ## | ||
go run cli/main.go --config config-files/node_config.anvil.yaml deposit-into-strategy --strategy-addr ${STRATEGY_ADDRESS} --amount 100 | ||
|
||
cli-register-operator-with-avs: ## | ||
go run cli/main.go --config config-files/node_config.anvil.yaml register-operator-with-avs | ||
|
||
cli-deregister-operator-with-avs: ## | ||
go run cli/main.go --config config-files/node_config.anvil.yaml deregister-operator-with-avs | ||
|
||
cli-print-operator-status: ## | ||
go run cli/main.go --config config-files/node_config.anvil.yaml print-operator-status | ||
|
||
send-fund: ## sends fund to the operator saved in tests/keys/test.ecdsa.key.json | ||
cast send 0x860B6912C2d0337ef05bbC89b0C2CB6CbAEAB4A5 --value 10ether --private-key 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6 | ||
|
||
-----------------------------: ## | ||
# We pipe all zapper logs through https://github.com/maoueh/zap-pretty so make sure to install it | ||
# TODO: piping to zap-pretty only works when zapper environment is set to production, unsure why | ||
____OFFCHAIN_SOFTWARE___: ## | ||
start-aggregator: ## | ||
go run aggregator/cmd/main.go --config config-files/aggregator.yaml \ | ||
--credible-squaring-deployment ${DEPLOYMENT_FILES_DIR}/credible_squaring_avs_deployment_output.json \ | ||
--shared-avs-contracts-deployment ${DEPLOYMENT_FILES_DIR}/shared_avs_contracts_deployment_output.json \ | ||
--ecdsa-private-key ${AGGREGATOR_ECDSA_PRIV_KEY} \ | ||
2>&1 | zap-pretty | ||
|
||
start-operator: ## | ||
go run operator/cmd/main.go --config config-files/node_config.anvil.yaml \ | ||
2>&1 | zap-pretty | ||
|
||
start-challenger: ## | ||
go run challenger/cmd/main.go --config config-files/challenger.yaml \ | ||
--credible-squaring-deployment ${DEPLOYMENT_FILES_DIR}/credible_squaring_avs_deployment_output.json \ | ||
--shared-avs-contracts-deployment ${DEPLOYMENT_FILES_DIR}/shared_avs_contracts_deployment_output.json \ | ||
--ecdsa-private-key ${CHALLENGER_ECDSA_PRIV_KEY} \ | ||
2>&1 | zap-pretty | ||
|
||
run-plugin: ## | ||
go run plugin/cmd/main.go --config config-files/node_config.anvil.yaml | ||
-----------------------------: ## | ||
_____HELPER_____: ## | ||
mocks: ## generates mocks for tests | ||
go install go.uber.org/mock/[email protected] | ||
go generate ./... | ||
|
||
tests-unit: ## runs all tests | ||
go test $$(go list ./... | grep -v /integration) -covermode=atomic --timeout 15s | ||
|
||
tests-unit-cover: ## run all tests with test coverge | ||
go test $$(go list ./... | grep -v /integration) -coverprofile=coverage.out -covermode=atomic -v -count=1 --timeout 15s | ||
go tool cover -html=coverage.out -o coverage.html | ||
|
||
tests-integration: ## runs all integration tests | ||
go test ./tests/integration/... -v -count=1 --timeout 60s | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Incredible Squaring AVS | ||
|
||
<b> Do not use it in Production, testnet only. </b> | ||
|
||
Basic repo demoing a simple AVS middleware with full eigenlayer integration. | ||
|
||
## Running via make | ||
|
||
This simple session illustrates the basic flow of the AVS. The makefile commands are hardcoded for a single operator, but it's however easy to create new operator config files, and start more operators manually (see the actual commands that the makefile calls). | ||
|
||
Start anvil in a separate terminal: | ||
|
||
```bash | ||
make start-anvil-chain-with-el-and-avs-deployed | ||
``` | ||
|
||
The above command starts a local anvil chain from a [saved state](./tests/integration/eigenlayer-and-shared-avs-contracts-deployed-anvil-state.json) with eigenlayer and incredible-squaring contracts already deployed (but no operator registered). | ||
|
||
Start the aggregator: | ||
|
||
```bash | ||
make start-aggregator | ||
``` | ||
|
||
Register the operator with eigenlayer and incredible-squaring, and then start the process: | ||
|
||
```bash | ||
make cli-setup-operator | ||
make start-operator | ||
``` | ||
|
||
## Running via docker compose | ||
|
||
We wrote a [docker-compose.yml](./docker-compose.yml) file to run and test everything on a single machine. It will start an anvil instance, loading a [state](./tests/integration/avs-and-eigenlayer-deployed-anvil-state.json) where the eigenlayer and incredible-squaring contracts are deployed, start the aggregator, and finally one operator, along with prometheus and grafana servers. The grafana server will be available at http://localhost:3000, with user and password both set to `admin`. We have created a simple [grafana dashboard](./grafana/provisioning/dashboards/AVSs/incredible_squaring.json) which can be used as a starting example and expanded to include AVS specific metrics. The eigen metrics should not be added to this dashboard as they will be exposed on the main eigenlayer dashboard provided by the eigenlayer-cli. | ||
|
||
## Avs Task Description | ||
|
||
The architecture of the AVS contains: | ||
|
||
- [Eigenlayer core](https://github.com/Layr-Labs/eigenlayer-contracts/tree/master) contracts | ||
- AVS contracts | ||
- [ServiceManager](contracts/src/CredibleSquaringServiceManager.sol) which contains the [slashing](contracts/src/CredibleSquaringServiceManager.sol#L63) logic. | ||
- [TaskManager](contracts/src/CredibleSquaringTaskManager.sol) which contains [task creation](contracts/src/CredibleSquaringTaskManager.sol#L75) and [task response](contracts/src/CredibleSquaringTaskManager.sol#L102) logic. | ||
- The [challenge](contracts/src/CredibleSquaringTaskManager.sol#L185) logic could be separated into its own contract, but we have decided to include it in the TaskManager for this simple task. | ||
- Set of [registry contracts](https://github.com/Layr-Labs/eigenlayer-middleware) to manage operators opted in to this avs | ||
- Task Generator | ||
- in a real world scenario, this could be a separate entity, but for this simple demo, the aggregator also acts as the task generator | ||
- Aggregator | ||
- aggregates BLS signatures from operators and posts the aggregated response to the task manager | ||
- For this simple demo, the aggregator is not an operator, and thus does not need to register with eigenlayer or the AVS contract. It's IP address is simply hardcoded into the operators' config. | ||
- Operators | ||
- Square the number sent to the task manager by the task generator, sign it, and send it to the aggregator | ||
|
||
 | ||
|
||
1. A task generator (in our case, same as the aggregator) publishes tasks once every regular interval (say 10 blocks, you are free to set your own interval) to the CredibleSquaringTaskManager contract's [createNewTask](contracts/src/CredibleSquaringTaskManager.sol#L78) function. Each task specifies an integer `numberToBeSquared` for which it wants the currently opted-in operators to determine its square `numberToBeSquared^2`. `createNewTask` also takes `quorumNumbers` and `quorumThresholdPercentage` which requests that each listed quorum (we only use quorumNumber 0 in incredible-squaring) needs to reach at least thresholdPercentage of operator signatures. | ||
|
||
2. A [registry](https://github.com/Layr-Labs/eigenlayer-middleware/blob/master/src/BLSRegistryCoordinatorWithIndices.sol) contract is deployed that allows any eigenlayer operator with at least 1 delegated [mockerc20](contracts/src/ERC20Mock.sol) token to opt-in to this AVS and also de-register from this AVS. | ||
|
||
3. [Operator] The operators who are currently opted-in with the AVS need to read the task number from the Task contract, compute its square, sign on that computed result (over the BN254 curve) and send their taskResponse and signature to the aggregator. | ||
|
||
4. [Aggregator] The aggregator collects the signatures from the operators and aggregates them using BLS aggregation. If any response passes the [quorumThresholdPercentage](contracts/src/ICredibleSquaringTaskManager.sol#L36) set by the task generator when posting the task, the aggregator posts the aggregated response to the Task contract. | ||
|
||
5. If a response was sent within the [response window](contracts/src/CredibleSquaringTaskManager.sol#L119), we enter the [Dispute resolution] period. | ||
- [Off-chain] A challenge window is launched during which anyone can [raise a dispute](contracts/src/CredibleSquaringTaskManager.sol#L171) in a DisputeResolution contract (in our case, this is the same as the TaskManager contract) | ||
- [On-chain] The DisputeResolution contract resolves that a particular operator’s response is not the correct response (that is, not the square of the integer specified in the task) or the opted-in operator didn’t respond during the response window. If the dispute is resolved, the operator will be frozen in the Registration contract and the veto committee will decide whether to veto the freezing request or not. | ||
|
||
Below is a more detailed uml diagram of the aggregator and operator processes: | ||
|
||
 | ||
|
||
## Integration Tests | ||
|
||
See the integration tests [README](tests/integration/README.md) for more details. |
Oops, something went wrong.