Skip to content

Commit

Permalink
Merge pull request #2 from Layr-Labs/samlaf/update-contract-names-to-inc
Browse files Browse the repository at this point in the history
updated all contract names to use incredible instead of credible
  • Loading branch information
samlaf authored Oct 26, 2023
2 parents ed90bc7 + 56d8082 commit 4518b96
Show file tree
Hide file tree
Showing 38 changed files with 2,415 additions and 2,361 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ 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.
- [ServiceManager](contracts/src/IncredibleSquaringServiceManager.sol) which contains the [slashing](contracts/src/IncredibleSquaringServiceManager.sol#L63) logic.
- [TaskManager](contracts/src/IncredibleSquaringTaskManager.sol) which contains [task creation](contracts/src/IncredibleSquaringTaskManager.sol#L75) and [task response](contracts/src/IncredibleSquaringTaskManager.sol#L102) logic.
- The [challenge](contracts/src/IncredibleSquaringTaskManager.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
Expand All @@ -53,16 +53,16 @@ The architecture of the AVS contains:

![](./diagrams/architecture.png)

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.
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 IncredibleSquaringTaskManager contract's [createNewTask](contracts/src/IncredibleSquaringTaskManager.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.
4. [Aggregator] The aggregator collects the signatures from the operators and aggregates them using BLS aggregation. If any response passes the [quorumThresholdPercentage](contracts/src/IIncredibleSquaringTaskManager.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)
5. If a response was sent within the [response window](contracts/src/IncredibleSquaringTaskManager.sol#L119), we enter the [Dispute resolution] period.
- [Off-chain] A challenge window is launched during which anyone can [raise a dispute](contracts/src/IncredibleSquaringTaskManager.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:
Expand Down
10 changes: 5 additions & 5 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/Layr-Labs/incredible-squaring-avs/core/chainio"
"github.com/Layr-Labs/incredible-squaring-avs/core/config"

cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/CredibleSquaringTaskManager"
cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/IncredibleSquaringTaskManager"
)

const (
Expand Down Expand Up @@ -71,9 +71,9 @@ type Aggregator struct {
avsWriter chainio.AvsWriterer
// aggregation related fields
blsAggregationService blsagg.BlsAggregationService
tasks map[types.TaskIndex]cstaskmanager.ICredibleSquaringTaskManagerTask
tasks map[types.TaskIndex]cstaskmanager.IIncredibleSquaringTaskManagerTask
tasksMu sync.RWMutex
taskResponses map[types.TaskIndex]map[sdktypes.TaskResponseDigest]cstaskmanager.ICredibleSquaringTaskManagerTaskResponse
taskResponses map[types.TaskIndex]map[sdktypes.TaskResponseDigest]cstaskmanager.IIncredibleSquaringTaskManagerTaskResponse
taskResponsesMu sync.RWMutex
}

Expand Down Expand Up @@ -143,8 +143,8 @@ func NewAggregator(c *config.Config) (*Aggregator, error) {
serverIpPortAddr: c.AggregatorServerIpPortAddr,
avsWriter: avsWriter,
blsAggregationService: blsAggregationService,
tasks: make(map[types.TaskIndex]cstaskmanager.ICredibleSquaringTaskManagerTask),
taskResponses: make(map[types.TaskIndex]map[sdktypes.TaskResponseDigest]cstaskmanager.ICredibleSquaringTaskManagerTaskResponse),
tasks: make(map[types.TaskIndex]cstaskmanager.IIncredibleSquaringTaskManagerTask),
taskResponses: make(map[types.TaskIndex]map[sdktypes.TaskResponseDigest]cstaskmanager.IIncredibleSquaringTaskManagerTaskResponse),
}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions aggregator/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/Layr-Labs/incredible-squaring-avs/aggregator/mocks"
"github.com/Layr-Labs/incredible-squaring-avs/aggregator/types"
cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/CredibleSquaringTaskManager"
cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/IncredibleSquaringTaskManager"
chainiomocks "github.com/Layr-Labs/incredible-squaring-avs/core/chainio/mocks"
)

Expand Down Expand Up @@ -87,8 +87,8 @@ func createMockAggregator(
logger: logger,
avsWriter: mockAvsWriter,
blsAggregationService: mockBlsAggregationService,
tasks: make(map[types.TaskIndex]cstaskmanager.ICredibleSquaringTaskManagerTask),
taskResponses: make(map[types.TaskIndex]map[sdktypes.TaskResponseDigest]cstaskmanager.ICredibleSquaringTaskManagerTaskResponse),
tasks: make(map[types.TaskIndex]cstaskmanager.IIncredibleSquaringTaskManagerTask),
taskResponses: make(map[types.TaskIndex]map[sdktypes.TaskResponseDigest]cstaskmanager.IIncredibleSquaringTaskManagerTaskResponse),
}
return aggregator, mockAvsWriter, mockBlsAggregationService, nil
}
Expand Down
6 changes: 3 additions & 3 deletions aggregator/mocks/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
opstateretriever "github.com/Layr-Labs/eigensdk-go/contracts/bindings/BLSOperatorStateRetriever"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/Layr-Labs/incredible-squaring-avs/aggregator/types"
cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/CredibleSquaringTaskManager"
cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/IncredibleSquaringTaskManager"
)

// ====== TaskManager Mocks ======

func MockSendNewTaskNumberToSquareCall(blockNum, taskNum, numberToSquare uint32) (cstaskmanager.ICredibleSquaringTaskManagerTask, uint32, error) {
task := cstaskmanager.ICredibleSquaringTaskManagerTask{
func MockSendNewTaskNumberToSquareCall(blockNum, taskNum, numberToSquare uint32) (cstaskmanager.IIncredibleSquaringTaskManagerTask, uint32, error) {
task := cstaskmanager.IIncredibleSquaringTaskManagerTask{
NumberToBeSquared: big.NewInt(int64(numberToSquare)),
TaskCreatedBlock: blockNum,
QuorumNumbers: types.QUORUM_NUMBERS,
Expand Down
6 changes: 3 additions & 3 deletions aggregator/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"net/rpc"

cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/CredibleSquaringTaskManager"
cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/IncredibleSquaringTaskManager"
"github.com/Layr-Labs/incredible-squaring-avs/core"

"github.com/Layr-Labs/eigensdk-go/crypto/bls"
Expand Down Expand Up @@ -38,7 +38,7 @@ func (agg *Aggregator) startServer(ctx context.Context) error {
}

type SignedTaskResponse struct {
TaskResponse cstaskmanager.ICredibleSquaringTaskManagerTaskResponse
TaskResponse cstaskmanager.IIncredibleSquaringTaskManagerTaskResponse
BlsSignature bls.Signature
OperatorId bls.OperatorId
}
Expand All @@ -56,7 +56,7 @@ func (agg *Aggregator) ProcessSignedTaskResponse(signedTaskResponse *SignedTaskR
}
agg.taskResponsesMu.Lock()
if _, ok := agg.taskResponses[taskIndex]; !ok {
agg.taskResponses[taskIndex] = make(map[sdktypes.TaskResponseDigest]cstaskmanager.ICredibleSquaringTaskManagerTaskResponse)
agg.taskResponses[taskIndex] = make(map[sdktypes.TaskResponseDigest]cstaskmanager.IIncredibleSquaringTaskManagerTaskResponse)
}
if _, ok := agg.taskResponses[taskIndex][taskResponseDigest]; !ok {
agg.taskResponses[taskIndex][taskResponseDigest] = signedTaskResponse.TaskResponse
Expand Down
4 changes: 2 additions & 2 deletions aggregator/rpc_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
sdktypes "github.com/Layr-Labs/eigensdk-go/types"
"github.com/Layr-Labs/incredible-squaring-avs/aggregator/types"
cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/CredibleSquaringTaskManager"
cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/IncredibleSquaringTaskManager"
"github.com/Layr-Labs/incredible-squaring-avs/core"
)

Expand Down Expand Up @@ -63,7 +63,7 @@ func TestProcessSignedTaskResponse(t *testing.T) {
// mocks an operator signing on a task response
func createMockSignedTaskResponse(mockTask MockTask, keypair bls.KeyPair) (*SignedTaskResponse, error) {
numberToSquareBigInt := big.NewInt(int64(mockTask.NumberToSquare))
taskResponse := &cstaskmanager.ICredibleSquaringTaskManagerTaskResponse{
taskResponse := &cstaskmanager.IIncredibleSquaringTaskManagerTaskResponse{
ReferenceTaskIndex: mockTask.TaskNum,
NumberSquared: numberToSquareBigInt.Mul(numberToSquareBigInt, numberToSquareBigInt),
}
Expand Down
22 changes: 11 additions & 11 deletions challenger/challenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi"

"github.com/Layr-Labs/incredible-squaring-avs/challenger/types"
cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/CredibleSquaringTaskManager"
cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/IncredibleSquaringTaskManager"
"github.com/Layr-Labs/incredible-squaring-avs/core/chainio"
)

Expand All @@ -22,10 +22,10 @@ type Challenger struct {
avsReader chainio.AvsReaderer
avsWriter chainio.AvsWriterer
avsSubscriber chainio.AvsSubscriberer
tasks map[uint32]cstaskmanager.ICredibleSquaringTaskManagerTask
tasks map[uint32]cstaskmanager.IIncredibleSquaringTaskManagerTask
taskResponses map[uint32]types.TaskResponseData
taskResponseChan chan *cstaskmanager.ContractCredibleSquaringTaskManagerTaskResponded
newTaskCreatedChan chan *cstaskmanager.ContractCredibleSquaringTaskManagerNewTaskCreated
taskResponseChan chan *cstaskmanager.ContractIncredibleSquaringTaskManagerTaskResponded
newTaskCreatedChan chan *cstaskmanager.ContractIncredibleSquaringTaskManagerNewTaskCreated
}

func NewChallenger(c *config.Config) (*Challenger, error) {
Expand All @@ -52,10 +52,10 @@ func NewChallenger(c *config.Config) (*Challenger, error) {
avsWriter: avsWriter,
avsReader: avsReader,
avsSubscriber: avsSubscriber,
tasks: make(map[uint32]cstaskmanager.ICredibleSquaringTaskManagerTask),
tasks: make(map[uint32]cstaskmanager.IIncredibleSquaringTaskManagerTask),
taskResponses: make(map[uint32]types.TaskResponseData),
taskResponseChan: make(chan *cstaskmanager.ContractCredibleSquaringTaskManagerTaskResponded),
newTaskCreatedChan: make(chan *cstaskmanager.ContractCredibleSquaringTaskManagerNewTaskCreated),
taskResponseChan: make(chan *cstaskmanager.ContractIncredibleSquaringTaskManagerTaskResponded),
newTaskCreatedChan: make(chan *cstaskmanager.ContractIncredibleSquaringTaskManagerNewTaskCreated),
}

return challenger, nil
Expand Down Expand Up @@ -112,12 +112,12 @@ func (c *Challenger) Start(ctx context.Context) error {

}

func (c *Challenger) processNewTaskCreatedLog(newTaskCreatedLog *cstaskmanager.ContractCredibleSquaringTaskManagerNewTaskCreated) uint32 {
func (c *Challenger) processNewTaskCreatedLog(newTaskCreatedLog *cstaskmanager.ContractIncredibleSquaringTaskManagerNewTaskCreated) uint32 {
c.tasks[newTaskCreatedLog.TaskIndex] = newTaskCreatedLog.Task
return newTaskCreatedLog.TaskIndex
}

func (c *Challenger) processTaskResponseLog(taskResponseLog *cstaskmanager.ContractCredibleSquaringTaskManagerTaskResponded) uint32 {
func (c *Challenger) processTaskResponseLog(taskResponseLog *cstaskmanager.ContractIncredibleSquaringTaskManagerTaskResponded) uint32 {
taskResponseRawLog, err := c.avsSubscriber.ParseTaskResponded(taskResponseLog.Raw)
if err != nil {
c.logger.Error("Error parsing task response. skipping task (this is probably bad and should be investigated)", "err", err)
Expand Down Expand Up @@ -152,7 +152,7 @@ func (c *Challenger) callChallengeModule(taskIndex uint32) error {
return types.NoErrorInTaskResponse
}

func (c *Challenger) getNonSigningOperatorPubKeys(vLog *cstaskmanager.ContractCredibleSquaringTaskManagerTaskResponded) []cstaskmanager.BN254G1Point {
func (c *Challenger) getNonSigningOperatorPubKeys(vLog *cstaskmanager.ContractIncredibleSquaringTaskManagerTaskResponded) []cstaskmanager.BN254G1Point {
c.logger.Info("vLog.Raw is", "vLog.Raw", vLog.Raw)

// get the nonSignerStakesAndSignature
Expand All @@ -168,7 +168,7 @@ func (c *Challenger) getNonSigningOperatorPubKeys(vLog *cstaskmanager.ContractCr
}
calldata := tx.Data()
c.logger.Info("calldata", "calldata", calldata)
cstmAbi, err := abi.JSON(bytes.NewReader(common.CredibleSquaringTaskManagerAbi))
cstmAbi, err := abi.JSON(bytes.NewReader(common.IncredibleSquaringTaskManagerAbi))
if err != nil {
c.logger.Error("Error getting Abi", "err", err)
}
Expand Down
Loading

0 comments on commit 4518b96

Please sign in to comment.