Skip to content

Commit

Permalink
fix testnet
Browse files Browse the repository at this point in the history
+ add deploy script to setup strategy & token for anvil
+ aggregator defensive checks
+ fix makefile
+ fix CI
+ deploy configs for contracts
  • Loading branch information
vanderian committed Dec 20, 2023
1 parent ea57fcc commit 28f04b0
Show file tree
Hide file tree
Showing 26 changed files with 525 additions and 641 deletions.
136 changes: 96 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ help:
AGGREGATOR_ECDSA_PRIV_KEY=0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6
CHALLENGER_ECDSA_PRIV_KEY=0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a

CHAINID=31337
ETH_RPC_URL=http://localhost:8545
ETH_WS_URL=ws://localhost:8545
SUBSTRATE_RPC_URL=wss://kusama-archive.mangata.online
AGGREGATOR_RPC_URL=localhost:8090

CHAIN_ID=31337

BLS_PUBLIC_KEY_COMPENDIUM=0xc5a5C42992dECbae36851359345FE25997F5C42d
BLS_OPERATOR_STATE_RETRIEVER=0x67d269191c92Caf3cD7723F116c85e6E9bf55933
AVS_SERVICE_MANAGER=0x9E545E3C0baAB3E08CdfD552C960A1050f373042

# 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
# check in contracts/script/output/${CHAINID}/strategy_output.json
STRATEGY_ADDRESS=0x4A679253410272dd5232B3Ff7cF5dbB88f295319
DEPLOYMENT_FILES_DIR=contracts/script/output/${CHAINID}

-----------------------------: ##
Expand All @@ -23,47 +33,85 @@ deploy-eigenlayer-contracts-to-anvil-and-save-state: ## Deploy eigenlayer
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
deploy-avs-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
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-avs-contracts-to-anvil-and-save-state ## deploy eigenlayer, shared avs contracts, and avs 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
docker buildx build --load --platform linux/amd64,linux/arm64 -t mangatasolutions/aggregator:latest -f aggregator/Dockerfile .
docker buildx build --load --platform linux/amd64,linux/arm64 -t mangatasolutions/operator:latest -f operator/Dockerfile .
# KO_DOCKER_REPO=mangatasolutions/aggregator ko build --bare aggregator/cmd/main.go --platform=linux/arm64,linux/amd64
# KO_DOCKER_REPO=mangatasolutions/operator ko build --bare operator/cmd/main.go --platform=linux/arm64,linux/amd64
docker-start-everything: docker-build-and-publish-images ## starts aggregator and operator docker containers
docker compose pull && docker compose up
# ___DOCKER___: ##
# docker-build-and-publish-images: ## builds and publishes operator and aggregator docker images using Ko
# docker buildx build --load --platform linux/amd64,linux/arm64 -t mangatasolutions/aggregator:latest -f aggregator/Dockerfile .
# docker buildx build --load --platform linux/amd64,linux/arm64 -t mangatasolutions/operator:latest -f operator/Dockerfile .
# # KO_DOCKER_REPO=mangatasolutions/aggregator ko build --bare aggregator/cmd/main.go --platform=linux/arm64,linux/amd64
# # KO_DOCKER_REPO=mangatasolutions/operator ko build --bare operator/cmd/main.go --platform=linux/arm64,linux/amd64
# docker-start-everything: docker-build-and-publish-images ## starts aggregator and operator docker containers
# docker compose pull && docker compose up

__CLI__: ##
# __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-setup-operator: cli-register-operator-with-eigenlayer 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/operator.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/operator.anvil.yaml register-operator-bls-pubkeys

cli-deposit-into-mocktoken-strategy: ##
go run cli/main.go --config config-files/operator.anvil.yaml deposit-into-strategy --strategy-addr ${STRATEGY_ADDRESS} --amount 100
go run operator/plugin/cmd/main.go \
--eth-rpc-url ${ETH_RPC_URL} \
--eth-ws-url ${ETH_WS_URL} \
--substrate-rpc-url ${SUBSTRATE_RPC_URL} \
--aggregator-rpc-url ${AGGREGATOR_RPC_URL} \
--chain-id ${CHAIN_ID} \
--bls-public-key-compendium ${BLS_PUBLIC_KEY_COMPENDIUM} \
--bls-operator-state-retriever ${BLS_OPERATOR_STATE_RETRIEVER} \
--avs-service-manager ${AVS_SERVICE_MANAGER} \
--ecdsa-key-file tests/keys/test.ecdsa.key.json \
--bls-key-file tests/keys/test.bls.key.json \
register-operator-with-eigen

cli-register-operator-with-avs: ##
go run cli/main.go --config config-files/operator.anvil.yaml register-operator-with-avs
go run operator/plugin/cmd/main.go \
--eth-rpc-url ${ETH_RPC_URL} \
--eth-ws-url ${ETH_WS_URL} \
--substrate-rpc-url ${SUBSTRATE_RPC_URL} \
--aggregator-rpc-url ${AGGREGATOR_RPC_URL} \
--chain-id ${CHAIN_ID} \
--bls-public-key-compendium ${BLS_PUBLIC_KEY_COMPENDIUM} \
--bls-operator-state-retriever ${BLS_OPERATOR_STATE_RETRIEVER} \
--avs-service-manager ${AVS_SERVICE_MANAGER} \
--ecdsa-key-file tests/keys/test.ecdsa.key.json \
--bls-key-file tests/keys/test.bls.key.json \
register-operator-with-avs

cli-deregister-operator-with-avs: ##
go run cli/main.go --config config-files/operator.anvil.yaml deregister-operator-with-avs
go run operator/plugin/cmd/main.go \
--eth-rpc-url ${ETH_RPC_URL} \
--eth-ws-url ${ETH_WS_URL} \
--substrate-rpc-url ${SUBSTRATE_RPC_URL} \
--aggregator-rpc-url ${AGGREGATOR_RPC_URL} \
--chain-id ${CHAIN_ID} \
--bls-public-key-compendium ${BLS_PUBLIC_KEY_COMPENDIUM} \
--bls-operator-state-retriever ${BLS_OPERATOR_STATE_RETRIEVER} \
--avs-service-manager ${AVS_SERVICE_MANAGER} \
--ecdsa-key-file tests/keys/test.ecdsa.key.json \
--bls-key-file tests/keys/test.bls.key.json \
register-operator-with-avs

cli-print-operator-status: ##
go run cli/main.go --config config-files/operator.anvil.yaml print-operator-status
go run operator/plugin/cmd/main.go \
--eth-rpc-url ${ETH_RPC_URL} \
--eth-ws-url ${ETH_WS_URL} \
--substrate-rpc-url ${SUBSTRATE_RPC_URL} \
--aggregator-rpc-url ${AGGREGATOR_RPC_URL} \
--chain-id ${CHAIN_ID} \
--bls-public-key-compendium ${BLS_PUBLIC_KEY_COMPENDIUM} \
--bls-operator-state-retriever ${BLS_OPERATOR_STATE_RETRIEVER} \
--avs-service-manager ${AVS_SERVICE_MANAGER} \
--ecdsa-key-file tests/keys/test.ecdsa.key.json \
--bls-key-file tests/keys/test.bls.key.json \
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
Expand All @@ -72,26 +120,34 @@ send-fund: ## sends fund to the operator saved in tests/keys/test.ecdsa.key.json
# 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} \
start-aggregator: ##
go run aggregator/cmd/main.go \
--eth-rpc-url ${ETH_RPC_URL} \
--eth-ws-url ${ETH_WS_URL} \
--substrate-rpc-url ${SUBSTRATE_RPC_URL} \
--chain-id ${CHAIN_ID} \
--bls-public-key-compendium ${BLS_PUBLIC_KEY_COMPENDIUM} \
--bls-operator-state-retriever ${BLS_OPERATOR_STATE_RETRIEVER} \
--avs-service-manager ${AVS_SERVICE_MANAGER} \
--ecdsa-key-file ./tests/keys/aggregator.ecdsa.key.json \
--avs-server-ip-port-address ${AGGREGATOR_RPC_URL} \
2>&1 | zap-pretty

start-operator: ##
go run operator/cmd/main.go --config config-files/operator.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} \
go run operator/cmd/main.go \
--eth-rpc-url ${ETH_RPC_URL} \
--eth-ws-url ${ETH_WS_URL} \
--substrate-rpc-url ${SUBSTRATE_RPC_URL} \
--aggregator-rpc-url ${AGGREGATOR_RPC_URL} \
--chain-id ${CHAIN_ID} \
--bls-public-key-compendium ${BLS_PUBLIC_KEY_COMPENDIUM} \
--bls-operator-state-retriever ${BLS_OPERATOR_STATE_RETRIEVER} \
--avs-service-manager ${AVS_SERVICE_MANAGER} \
--ecdsa-key-file tests/keys/test.ecdsa.key.json \
--bls-key-file tests/keys/test.bls.key.json \
--register-at-startup true
2>&1 | zap-pretty

run-plugin: ##
go run plugin/cmd/main.go --config config-files/operator.anvil.yaml
-----------------------------: ##
_____HELPER_____: ##
mocks: ## generates mocks for tests
Expand Down
37 changes: 19 additions & 18 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ type Aggregator struct {
serverIpPortAddr string
avsWriter chainio.AvsWriterer
// aggregation related fields
blsAggregationService blsagg.BlsAggregationService
tasks map[types.TaskIndex]taskmanager.IMangataTaskManagerTask
tasksMu sync.RWMutex
taskResponses map[types.TaskIndex]map[sdktypes.TaskResponseDigest]taskmanager.IMangataTaskManagerTaskResponse
taskResponsesMu sync.RWMutex
substrateClient gsrpc.SubstrateAPI
taskChallengeWindowBlock uint32
blsAggregationService blsagg.BlsAggregationService
tasks map[types.TaskIndex]taskmanager.IMangataTaskManagerTask
tasksMu sync.RWMutex
taskResponses map[types.TaskIndex]map[sdktypes.TaskResponseDigest]taskmanager.IMangataTaskManagerTaskResponse
taskResponsesMu sync.RWMutex
substrateClient gsrpc.SubstrateAPI
taskResponseWindowBlock uint32
}

// NewAggregator creates a new Aggregator with the provided config.
Expand Down Expand Up @@ -156,7 +156,7 @@ func NewAggregator(c *Config) (*Aggregator, error) {
return nil, err
}

taskChallengeWindowBlock, err := avsReader.AvsServiceBindings.TaskManager.TASKCHALLENGEWINDOWBLOCK(&bind.CallOpts{})
taskResponseWindowBlock, err := avsReader.AvsServiceBindings.TaskManager.GetTaskResponseWindowBlock(&bind.CallOpts{})
if err != nil {
logger.Error("Cannot get taskChallengeWindowBlock from TaskManager contract", "err", err)
return nil, err
Expand All @@ -173,14 +173,14 @@ func NewAggregator(c *Config) (*Aggregator, error) {
}

return &Aggregator{
logger: logger,
serverIpPortAddr: c.ServerAddressPort,
avsWriter: avsWriter,
blsAggregationService: blsAggregationService,
tasks: make(map[types.TaskIndex]taskmanager.IMangataTaskManagerTask),
taskResponses: make(map[types.TaskIndex]map[sdktypes.TaskResponseDigest]taskmanager.IMangataTaskManagerTaskResponse),
substrateClient: *substrateRpc,
taskChallengeWindowBlock: taskChallengeWindowBlock,
logger: logger,
serverIpPortAddr: c.ServerAddressPort,
avsWriter: avsWriter,
blsAggregationService: blsAggregationService,
tasks: make(map[types.TaskIndex]taskmanager.IMangataTaskManagerTask),
taskResponses: make(map[types.TaskIndex]map[sdktypes.TaskResponseDigest]taskmanager.IMangataTaskManagerTaskResponse),
substrateClient: *substrateRpc,
taskResponseWindowBlock: taskResponseWindowBlock,
}, nil
}

Expand Down Expand Up @@ -218,6 +218,7 @@ func (agg *Aggregator) sendAggregatedResponseToContract(blsAggServiceResp blsagg
agg.logger.Warn("Task expired", "err", blsAggServiceResp.Err)
// panicing to help with debugging (fail fast), but we shouldn't panic if we run this in production
// panic(blsAggServiceResp.Err)
return
}
nonSignerPubkeys := []taskmanager.BN254G1Point{}
for _, nonSignerPubkey := range blsAggServiceResp.NonSignersPubkeysG1 {
Expand Down Expand Up @@ -279,8 +280,8 @@ func (agg *Aggregator) sendNewTask(header gsrpc_types.Header) error {
}
// TODO(samlaf): we use seconds for now, but we should ideally pass a blocknumber to the blsAggregationService
// and it should monitor the chain and only expire the task aggregation once the chain has reached that block number.
taskTimeToExpiry := time.Duration(agg.taskChallengeWindowBlock) * blockTimeSeconds
taskTimeToExpiry := time.Duration(agg.taskResponseWindowBlock) * blockTimeSeconds
agg.blsAggregationService.InitializeNewTask(taskIndex, newTask.TaskCreatedBlock, newTask.QuorumNumbers, quorumThresholdPercentages, taskTimeToExpiry)
agg.logger.Info("Aggregator initialized new task", "block number", blockNumber, "task index", taskIndex)
agg.logger.Info("Aggregator initialized new task", "block number", blockNumber, "task index", taskIndex, "expiry", taskTimeToExpiry)
return nil
}
5 changes: 5 additions & 0 deletions aggregator/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
var (
TaskNotFoundError400 = errors.New("400. Task not found")
OperatorNotPartOfTaskQuorum400 = errors.New("400. Operator not part of quorum")
OperatorNotRegistered400 = errors.New("400. Operator not registered in AVS")
TaskResponseDigestNotFoundError500 = errors.New("500. Failed to get task response digest")
UnknownErrorWhileVerifyingSignature400 = errors.New("400. Failed to verify signature")
SignatureVerificationFailed400 = errors.New("400. Signature verification failed")
Expand Down Expand Up @@ -54,6 +55,10 @@ func (agg *Aggregator) ProcessSignedTaskResponse(signedTaskResponse *SignedTaskR
agg.logger.Error("Failed to get task response digest", "err", err)
return TaskResponseDigestNotFoundError500
}
if signedTaskResponse.OperatorId == [32]byte{} {
agg.logger.Error("Operator not registered", "err", err)
return OperatorNotRegistered400
}
agg.taskResponsesMu.Lock()
if _, ok := agg.taskResponses[taskIndex]; !ok {
agg.taskResponses[taskIndex] = make(map[sdktypes.TaskResponseDigest]taskmanager.IMangataTaskManagerTaskResponse)
Expand Down
4 changes: 2 additions & 2 deletions aggregator/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

// TODO: Hardcoded for now
// all operators in quorum0 must sign the task response in order for it to be accepted
const QUORUM_THRESHOLD_NUMERATOR = uint32(100)
// 66% operators in quorum0 must sign the task response in order for it to be accepted
const QUORUM_THRESHOLD_NUMERATOR = uint32(66)
const QUORUM_THRESHOLD_DENOMINATOR = uint32(100)

const QUERY_FILTER_FROM_BLOCK = uint64(1)
Expand Down
Loading

0 comments on commit 28f04b0

Please sign in to comment.