From 6b1a4ae585b2c153341b502b8b80598d05dca0f1 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau <76252340+MarcosNicolau@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:25:12 -0300 Subject: [PATCH 1/2] fix: operator double signature (#1088) --- aggregator/internal/pkg/aggregator.go | 20 +---------- aggregator/internal/pkg/server.go | 26 +------------- core/chainio/avs_reader.go | 4 +-- core/chainio/avs_writer.go | 5 ++- core/chainio/bindings.go | 10 +++--- core/config/base.go | 35 ++++++++++++------- core/utils/eth_client_utils.go | 2 +- go.mod | 4 +-- go.sum | 4 +-- operator/cmd/actions/deposit_into_strategy.go | 8 ++--- operator/pkg/register.go | 9 ++--- 11 files changed, 44 insertions(+), 83 deletions(-) diff --git a/aggregator/internal/pkg/aggregator.go b/aggregator/internal/pkg/aggregator.go index 477112f68..b9bb73194 100644 --- a/aggregator/internal/pkg/aggregator.go +++ b/aggregator/internal/pkg/aggregator.go @@ -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 @@ -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) @@ -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{}, @@ -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 } @@ -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() @@ -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 } diff --git a/aggregator/internal/pkg/server.go b/aggregator/internal/pkg/server.go index c98ad3248..873259ecb 100644 --- a/aggregator/internal/pkg/server.go +++ b/aggregator/internal/pkg/server.go @@ -7,8 +7,6 @@ import ( "net/rpc" "time" - eigentypes "github.com/Layr-Labs/eigensdk-go/types" - "github.com/yetanotherco/aligned_layer/core/types" ) @@ -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) @@ -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") } diff --git a/core/chainio/avs_reader.go b/core/chainio/avs_reader.go index 78d46af78..60c42f137 100644 --- a/core/chainio/avs_reader.go +++ b/core/chainio/avs_reader.go @@ -48,10 +48,10 @@ func NewAvsReaderFromConfig(baseConfig *config.BaseConfig, ecdsaConfig *config.E } func (r *AvsReader) GetErc20Mock(tokenAddr gethcommon.Address) (*contractERC20Mock.ContractERC20Mock, error) { - erc20Mock, err := contractERC20Mock.NewContractERC20Mock(tokenAddr, r.AvsContractBindings.ethClient) + erc20Mock, err := contractERC20Mock.NewContractERC20Mock(tokenAddr, &r.AvsContractBindings.ethClient) if err != nil { // Retry with fallback client - erc20Mock, err = contractERC20Mock.NewContractERC20Mock(tokenAddr, r.AvsContractBindings.ethClientFallback) + erc20Mock, err = contractERC20Mock.NewContractERC20Mock(tokenAddr, &r.AvsContractBindings.ethClientFallback) if err != nil { r.logger.Error("Failed to fetch ERC20Mock contract", "err", err) } diff --git a/core/chainio/avs_writer.go b/core/chainio/avs_writer.go index f6c817358..a6a820195 100644 --- a/core/chainio/avs_writer.go +++ b/core/chainio/avs_writer.go @@ -23,8 +23,8 @@ type AvsWriter struct { AvsContractBindings *AvsServiceBindings logger logging.Logger Signer signer.Signer - Client eth.Client - ClientFallback eth.Client + Client eth.InstrumentedClient + ClientFallback eth.InstrumentedClient } func NewAvsWriterFromConfig(baseConfig *config.BaseConfig, ecdsaConfig *config.EcdsaConfig) (*AvsWriter, error) { @@ -119,7 +119,6 @@ func (w *AvsWriter) checkRespondToTaskFeeLimit(tx *types.Transaction, txOpts bin // Proceed to check values against simulated costs w.logger.Error("Failed to get batch state", "error", err) w.logger.Info("Proceeding with simulated cost checks") - return w.compareBalances(simulatedCost, aggregatorAddress, senderAddress) } } diff --git a/core/chainio/bindings.go b/core/chainio/bindings.go index 8aeb787d9..a0eb70478 100644 --- a/core/chainio/bindings.go +++ b/core/chainio/bindings.go @@ -12,19 +12,19 @@ import ( type AvsServiceBindings struct { ServiceManager *csservicemanager.ContractAlignedLayerServiceManager ServiceManagerFallback *csservicemanager.ContractAlignedLayerServiceManager - ethClient eth.Client - ethClientFallback eth.Client + ethClient eth.InstrumentedClient + ethClientFallback eth.InstrumentedClient logger logging.Logger } -func NewAvsServiceBindings(serviceManagerAddr, blsOperatorStateRetrieverAddr gethcommon.Address, ethClient eth.Client, ethClientFallback eth.Client, logger logging.Logger) (*AvsServiceBindings, error) { - contractServiceManager, err := csservicemanager.NewContractAlignedLayerServiceManager(serviceManagerAddr, ethClient) +func NewAvsServiceBindings(serviceManagerAddr, blsOperatorStateRetrieverAddr gethcommon.Address, ethClient eth.InstrumentedClient, ethClientFallback eth.InstrumentedClient, logger logging.Logger) (*AvsServiceBindings, error) { + contractServiceManager, err := csservicemanager.NewContractAlignedLayerServiceManager(serviceManagerAddr, ðClient) if err != nil { logger.Error("Failed to fetch AlignedLayerServiceManager contract", "err", err) return nil, err } - contractServiceManagerFallback, err := csservicemanager.NewContractAlignedLayerServiceManager(serviceManagerAddr, ethClientFallback) + contractServiceManagerFallback, err := csservicemanager.NewContractAlignedLayerServiceManager(serviceManagerAddr, ðClientFallback) if err != nil { logger.Error("Failed to fetch AlignedLayerServiceManager contract", "err", err) return nil, err diff --git a/core/config/base.go b/core/config/base.go index 65f639429..4eaef531b 100644 --- a/core/config/base.go +++ b/core/config/base.go @@ -9,7 +9,9 @@ import ( "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" sdklogging "github.com/Layr-Labs/eigensdk-go/logging" + rpccalls "github.com/Layr-Labs/eigensdk-go/metrics/collectors/rpc_calls" sdkutils "github.com/Layr-Labs/eigensdk-go/utils" + "github.com/prometheus/client_golang/prometheus" "github.com/urfave/cli/v2" ) @@ -27,10 +29,10 @@ type BaseConfig struct { Logger sdklogging.Logger EthRpcUrl string EthWsUrl string - EthRpcClient eth.Client - EthRpcClientFallback eth.Client - EthWsClient eth.Client - EthWsClientFallback eth.Client + EthRpcClient eth.InstrumentedClient + EthRpcClientFallback eth.InstrumentedClient + EthWsClient eth.InstrumentedClient + EthWsClientFallback eth.InstrumentedClient EigenMetricsIpPortAddress string ChainId *big.Int } @@ -96,12 +98,15 @@ func NewBaseConfig(configFilePath string) *BaseConfig { log.Fatal("Eth ws url or fallback is empty") } - ethWsClient, err := eth.NewClient(baseConfigFromYaml.EthWsUrl) + reg := prometheus.NewRegistry() + rpcCallsCollector := rpccalls.NewCollector("ethWs", reg) + ethWsClient, err := eth.NewInstrumentedClient(baseConfigFromYaml.EthWsUrl, rpcCallsCollector) if err != nil { log.Fatal("Error initializing eth ws client: ", err) } - - ethWsClientFallback, err := eth.NewClient(baseConfigFromYaml.EthWsUrlFallback) + reg = prometheus.NewRegistry() + rpcCallsCollector = rpccalls.NewCollector("ethWsFallback", reg) + ethWsClientFallback, err := eth.NewInstrumentedClient(baseConfigFromYaml.EthWsUrlFallback, rpcCallsCollector) if err != nil { log.Fatal("Error initializing eth ws client fallback: ", err) } @@ -110,12 +115,16 @@ func NewBaseConfig(configFilePath string) *BaseConfig { log.Fatal("Eth rpc url is empty") } - ethRpcClient, err := eth.NewClient(baseConfigFromYaml.EthRpcUrl) + reg = prometheus.NewRegistry() + rpcCallsCollector = rpccalls.NewCollector("ethRpc", reg) + ethRpcClient, err := eth.NewInstrumentedClient(baseConfigFromYaml.EthRpcUrl, rpcCallsCollector) if err != nil { log.Fatal("Error initializing eth rpc client: ", err) } - ethRpcClientFallback, err := eth.NewClient(baseConfigFromYaml.EthRpcUrlFallback) + reg = prometheus.NewRegistry() + rpcCallsCollector = rpccalls.NewCollector("ethRpc", reg) + ethRpcClientFallback, err := eth.NewInstrumentedClient(baseConfigFromYaml.EthRpcUrlFallback, rpcCallsCollector) if err != nil { log.Fatal("Error initializing eth rpc client fallback: ", err) } @@ -136,10 +145,10 @@ func NewBaseConfig(configFilePath string) *BaseConfig { Logger: logger, EthRpcUrl: baseConfigFromYaml.EthRpcUrl, EthWsUrl: baseConfigFromYaml.EthWsUrl, - EthRpcClient: ethRpcClient, - EthRpcClientFallback: ethRpcClientFallback, - EthWsClient: ethWsClient, - EthWsClientFallback: ethWsClientFallback, + EthRpcClient: *ethRpcClient, + EthRpcClientFallback: *ethRpcClientFallback, + EthWsClient: *ethWsClient, + EthWsClientFallback: *ethWsClientFallback, EigenMetricsIpPortAddress: baseConfigFromYaml.EigenMetricsIpPortAddress, ChainId: chainId, } diff --git a/core/utils/eth_client_utils.go b/core/utils/eth_client_utils.go index 25ae91776..afa26b867 100644 --- a/core/utils/eth_client_utils.go +++ b/core/utils/eth_client_utils.go @@ -15,7 +15,7 @@ import ( const maxRetries = 25 const sleepTime = 5 * time.Second -func WaitForTransactionReceipt(client eth.Client, ctx context.Context, txHash gethcommon.Hash) (*types.Receipt, error) { +func WaitForTransactionReceipt(client eth.InstrumentedClient, ctx context.Context, txHash gethcommon.Hash) (*types.Receipt, error) { for i := 0; i < maxRetries; i++ { receipt, err := client.TransactionReceipt(ctx, txHash) if err != nil { diff --git a/go.mod b/go.mod index 49da66f83..adcafe9ab 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/yetanotherco/aligned_layer go 1.22.2 require ( - github.com/Layr-Labs/eigensdk-go v0.1.9 + github.com/Layr-Labs/eigensdk-go v0.1.12 github.com/ethereum/go-ethereum v1.14.0 github.com/prometheus/client_golang v1.19.1 github.com/urfave/cli/v2 v2.27.1 @@ -91,5 +91,3 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect rsc.io/tmplfunc v0.0.3 // indirect ) - -replace github.com/Layr-Labs/eigensdk-go => github.com/yetanotherco/eigensdk-go v0.1.10-0.20240805154752-29f4d3457921 diff --git a/go.sum b/go.sum index ee02f6995..c1f032527 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOEl github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= +github.com/Layr-Labs/eigensdk-go v0.1.12 h1:Drf59iJLvnTm2Om9AwAyUMiZeJaTI8ZameIrnhjopSY= +github.com/Layr-Labs/eigensdk-go v0.1.12/go.mod h1:XcLVDtlB1vOPj63D236b451+SC75B8gwgkpNhYHSxNs= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8= @@ -315,8 +317,6 @@ github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= -github.com/yetanotherco/eigensdk-go v0.1.10-0.20240805154752-29f4d3457921 h1:bYER70hS8+Qx//uWWhm0+WymLTKHiqfbJkphteKUxPc= -github.com/yetanotherco/eigensdk-go v0.1.10-0.20240805154752-29f4d3457921/go.mod h1:XcLVDtlB1vOPj63D236b451+SC75B8gwgkpNhYHSxNs= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= diff --git a/operator/cmd/actions/deposit_into_strategy.go b/operator/cmd/actions/deposit_into_strategy.go index 47e2ffde5..d80ba6ffc 100644 --- a/operator/cmd/actions/deposit_into_strategy.go +++ b/operator/cmd/actions/deposit_into_strategy.go @@ -69,23 +69,23 @@ func depositIntoStrategyMain(ctx *cli.Context) error { if err != nil { return err } - w, err := wallet.NewPrivateKeyWallet(config.BaseConfig.EthRpcClient, signerFn, + w, err := wallet.NewPrivateKeyWallet(&config.BaseConfig.EthRpcClient, signerFn, config.Operator.Address, config.BaseConfig.Logger) if err != nil { return err } - txMgr := txmgr.NewSimpleTxManager(w, config.BaseConfig.EthRpcClient, config.BaseConfig.Logger, + txMgr := txmgr.NewSimpleTxManager(w, &config.BaseConfig.EthRpcClient, config.BaseConfig.Logger, config.Operator.Address) eigenMetrics := metrics.NewNoopMetrics() eigenLayerWriter, err := elcontracts.BuildELChainWriter(delegationManagerAddr, avsDirectoryAddr, - config.BaseConfig.EthRpcClient, config.BaseConfig.Logger, eigenMetrics, txMgr) + &config.BaseConfig.EthRpcClient, config.BaseConfig.Logger, eigenMetrics, txMgr) if err != nil { return err } - _, err = eigenLayerWriter.DepositERC20IntoStrategy(context.Background(), strategyAddr, amount) + _, err = eigenLayerWriter.DepositERC20IntoStrategy(context.Background(), strategyAddr, amount, true) if err != nil { config.BaseConfig.Logger.Errorf("Error depositing into strategy") return err diff --git a/operator/pkg/register.go b/operator/pkg/register.go index 1a8275515..76a0af3e1 100644 --- a/operator/pkg/register.go +++ b/operator/pkg/register.go @@ -2,8 +2,6 @@ package operator import ( "context" - "math/big" - "time" "github.com/Layr-Labs/eigensdk-go/types" "github.com/yetanotherco/aligned_layer/core/chainio" @@ -25,14 +23,13 @@ func RegisterOperator( return err } - operatorToAvsRegistrationSigExpiry := big.NewInt(time.Now().Add(10 * time.Minute).Unix()) socket := "Not Needed" quorumNumbers := types.QuorumNums{0} - _, err = writer.RegisterOperatorInQuorumWithAVSRegistryCoordinator(ctx, configuration.EcdsaConfig.PrivateKey, - operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry, configuration.BlsConfig.KeyPair, - quorumNumbers, socket) + _, err = writer.RegisterOperator(ctx, configuration.EcdsaConfig.PrivateKey, + configuration.BlsConfig.KeyPair, + quorumNumbers, socket, true) if err != nil { configuration.BaseConfig.Logger.Error("Failed to register operator", "err", err) From decd1c7b418efccc5ca5216a6516ef74b660ad47 Mon Sep 17 00:00:00 2001 From: Nacho Avecilla Date: Tue, 1 Oct 2024 15:30:04 -0300 Subject: [PATCH 2/2] feat: migrate cbor lib and add Fuzzer for cbor serialization (#1110) Co-authored-by: PatStiles Co-authored-by: Urix <43704209+uri-99@users.noreply.github.com> --- Makefile | 16 ++ common/proving_systems.go | 28 ++++ docs/3_guides/6_setup_aligned.md | 46 ++++-- .../aligned-integration/Cargo.lock | 149 ++++++++++-------- go.mod | 3 +- go.sum | 2 + operator/pkg/codec_mode.go | 10 ++ .../pkg/marshall_unmarshall_health_test.go | 32 ++++ operator/pkg/s3.go | 10 +- operator/pkg/valid_marshall_test.go | 32 ++++ 10 files changed, 238 insertions(+), 90 deletions(-) create mode 100644 operator/pkg/codec_mode.go create mode 100644 operator/pkg/marshall_unmarshall_health_test.go create mode 100644 operator/pkg/valid_marshall_test.go diff --git a/Makefile b/Makefile index 6e1c8be69..ccf5b2d1a 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/common/proving_systems.go b/common/proving_systems.go index 6b6a27f2d..28a0630a3 100644 --- a/common/proving_systems.go +++ b/common/proving_systems.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" "log" + + "github.com/fxamacker/cbor/v2" ) type ProvingSystemId uint16 @@ -96,6 +98,32 @@ func (t *ProvingSystemId) UnmarshalBinary(data []byte) error { return err } +func (s *ProvingSystemId) UnmarshalCBOR(data []byte) error { + var statusStr string + if err := cbor.Unmarshal(data, &statusStr); err != nil { + return err + } + + switch statusStr { + case "GnarkPlonkBls12_381": + *s = GnarkPlonkBls12_381 + case "GnarkPlonkBn254": + *s = GnarkPlonkBn254 + case "Groth16Bn254": + *s = Groth16Bn254 + case "SP1": + *s = SP1 + case "Halo2KZG": + *s = Halo2KZG + case "Halo2IPA": + *s = Halo2IPA + case "Risc0": + *s = Risc0 + } + + return nil +} + func (t ProvingSystemId) MarshalBinary() ([]byte, error) { // needs to be defined but should never be called return nil, fmt.Errorf("not implemented") diff --git a/docs/3_guides/6_setup_aligned.md b/docs/3_guides/6_setup_aligned.md index b9c64fd3b..ae3f5edde 100644 --- a/docs/3_guides/6_setup_aligned.md +++ b/docs/3_guides/6_setup_aligned.md @@ -50,11 +50,11 @@ Before starting, you need to set up an S3 bucket. More data storage will be test You need to fill the data in: -```batcher/aligned-batcher/.env``` +`batcher/aligned-batcher/.env` And you can use this file as an example of how to fill it: -```batcher/aligned-batcher/.env.example``` +`batcher/aligned-batcher/.env.example` After having the env setup, run in different terminals the following commands to boot Aligned locally: @@ -108,15 +108,15 @@ Note that when upgrading the contracts, you must also: 1. Re-generate the Go smart contract bindings: - ```bash - make bindings - ``` + ```bash + make bindings + ``` 2. Rebuild Aggregator and Operator Go binaries: - ```bash - make build_binaries - ``` + ```bash + make build_binaries + ``` @@ -324,7 +324,7 @@ batcher (`batcher/aligned-batcher/`). The necessary environment variables are: | Variable Name | Description | -|-----------------------|--------------------------------------------------------------------------------------------------------------------------------| +| --------------------- | ------------------------------------------------------------------------------------------------------------------------------ | | AWS_SECRET_ACCESS_KEY | Secret key to authenticate and authorize API requests to the AWS S3 Bucket. | | AWS_REGION | Geographical region where the AWS S3 Bucket will be accessed. | | AWS_ACCESS_KEY_ID | Access key used in combination with the AWS_SECRET_ACCESS_KEY to authenticate and authorize API requests to the AWS S3 Bucket. | @@ -660,7 +660,7 @@ Create a `.env` file in the `/explorer` directory of the project. The `.env` file needs to contain the following variables: | Variable | Description | -|-----------------------|-------------------------------------------------------------------------------------------------| +| --------------------- | ----------------------------------------------------------------------------------------------- | | `RPC_URL` | The RPC URL of the network you want to connect to. | | `ENVIRONMENT` | The environment you want to run the application in. It can be `devnet`, `holesky` or `mainnet`. | | `ALIGNED_CONFIG_FILE` | The config file containing Aligned contracts' deployment information | @@ -719,18 +719,34 @@ forge install Layr-Labs/eigenlayer-middleware@mainnet Then, to solve the issue, we changed it to: -```forge install yetanotherco/eigenlayer-middleware@yac-mainnet --no-commit``` +`forge install yetanotherco/eigenlayer-middleware@yac-mainnet --no-commit` As soon as it gets fixed in mainnet, we can revert it. -Base version of middleware used is ```7229f2b```. +Base version of middleware used is `7229f2b`. -The script to initialize the devnet can be found on ```contracts/scripts/anvil```. +The script to initialize the devnet can be found on `contracts/scripts/anvil`. The addresses of the relevant contracts after running the anvil script are dumped -on ```contracts/script/output/devnet```. +on `contracts/script/output/devnet`. -The state is backed up on ```contracts/scripts/anvil/state```. +The state is backed up on `contracts/scripts/anvil/state`. EigenLayer contract deployment is almost the same as the EigenLayer contract deployment on mainnet. Changes are described in the file. + +## Running Fuzzers: + +Fuzzing for the operator can be done by executing the following make commands from the root directory of the project. + +macOS: + +``` +make operator_verification_data_fuzz_macos +``` + +Linux: + +``` +operator_verification_data_fuzz_linux +``` diff --git a/examples/validating-public-input/aligned-integration/Cargo.lock b/examples/validating-public-input/aligned-integration/Cargo.lock index 2bd528635..2d6e9a36d 100644 --- a/examples/validating-public-input/aligned-integration/Cargo.lock +++ b/examples/validating-public-input/aligned-integration/Cargo.lock @@ -147,13 +147,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.82" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -175,14 +175,14 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "backtrace" @@ -313,9 +313,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" dependencies = [ "serde", ] @@ -375,9 +375,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.19" +version = "1.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d74707dde2ba56f86ae90effb3b43ddd369504387e718014de010cec7959800" +checksum = "3bbb537bb4a30b90362caddba8f360c0a56bc13d3a5570028e7197204cb54a17" dependencies = [ "jobserver", "libc", @@ -467,7 +467,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -536,9 +536,9 @@ checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "const-hex" -version = "1.12.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94fb8a24a26d37e1ffd45343323dc9fe6654ceea44c12f2fcb3d7ac29e610bc6" +checksum = "0121754e84117e65f9d90648ee6aa4882a6e63110307ab73967a4c5e7e69e586" dependencies = [ "cfg-if", "cpufeatures", @@ -688,7 +688,7 @@ checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -997,7 +997,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "syn 2.0.77", + "syn 2.0.79", "toml", "walkdir", ] @@ -1014,7 +1014,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1039,7 +1039,7 @@ dependencies = [ "serde", "serde_json", "strum", - "syn 2.0.77", + "syn 2.0.79", "tempfile", "thiserror", "tiny-keccak", @@ -1219,9 +1219,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.33" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" +checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" dependencies = [ "crc32fast", "miniz_oxide", @@ -1339,7 +1339,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1760,9 +1760,9 @@ dependencies = [ [[package]] name = "k256" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" dependencies = [ "cfg-if", "ecdsa", @@ -1841,9 +1841,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libm" @@ -2012,7 +2012,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2026,9 +2026,12 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" +dependencies = [ + "portable-atomic", +] [[package]] name = "open-fastrlp" @@ -2078,7 +2081,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2258,7 +2261,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2296,7 +2299,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2323,9 +2326,15 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" [[package]] name = "powerfmt" @@ -2355,7 +2364,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2482,9 +2491,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.4" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags 2.6.0", ] @@ -2502,9 +2511,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.6" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", @@ -2514,9 +2523,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", @@ -2525,9 +2534,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "reqwest" @@ -2847,9 +2856,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.11.1" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" dependencies = [ "core-foundation-sys", "libc", @@ -2893,7 +2902,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2916,14 +2925,14 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "serde_spanned" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" dependencies = [ "serde", ] @@ -3111,7 +3120,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3153,9 +3162,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -3197,9 +3206,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", "fastrand", @@ -3221,22 +3230,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3318,7 +3327,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3406,9 +3415,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.20" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", "serde", @@ -3442,7 +3451,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3547,18 +3556,18 @@ checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-normalization" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] [[package]] name = "unicode-xid" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "untrusted" @@ -3664,7 +3673,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-shared", ] @@ -3698,7 +3707,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3906,9 +3915,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] @@ -3975,7 +3984,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] diff --git a/go.mod b/go.mod index adcafe9ab..45a3e87e8 100644 --- a/go.mod +++ b/go.mod @@ -11,8 +11,10 @@ require ( ) require ( + github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 github.com/consensys/gnark v0.11.0 github.com/consensys/gnark-crypto v0.14.0 + github.com/fxamacker/cbor/v2 v2.7.0 github.com/ugorji/go/codec v1.2.12 ) @@ -47,7 +49,6 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/ethereum/c-kzg-4844 v1.0.3 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect - github.com/fxamacker/cbor/v2 v2.7.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect diff --git a/go.sum b/go.sum index c1f032527..cebd3061a 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8afgbRMd7mFxO99hRNu+6tazq8nFF9lIwo9JFroBk= +github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= diff --git a/operator/pkg/codec_mode.go b/operator/pkg/codec_mode.go new file mode 100644 index 000000000..17f02ce17 --- /dev/null +++ b/operator/pkg/codec_mode.go @@ -0,0 +1,10 @@ +package operator + +import ( + "github.com/fxamacker/cbor/v2" +) + +func createDecoderMode() (cbor.DecMode, error) { + // Use the max value for length of an array to correctly decode the batch. + return cbor.DecOptions{MaxArrayElements: 2147483647}.DecMode() +} diff --git a/operator/pkg/marshall_unmarshall_health_test.go b/operator/pkg/marshall_unmarshall_health_test.go new file mode 100644 index 000000000..da39971cb --- /dev/null +++ b/operator/pkg/marshall_unmarshall_health_test.go @@ -0,0 +1,32 @@ +package operator + +import ( + "bytes" + "testing" + + "github.com/fxamacker/cbor/v2" +) + +// Test roundtrip of cbor serialization and deserialization used in Aligned to verify that it doesn't panic. +func FuzzMarshalUnmarshal(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte, seed int64) { + // MarshalUnmarshal + + var unmarshalled VerificationData + decoder, err := createDecoderMode() + if err != nil { + return + } + err = decoder.Unmarshal(data, &unmarshalled) + if err != nil { + return + } + + var marshalled []byte + encoder := cbor.NewEncoder(bytes.NewBuffer(marshalled)) + err = encoder.Encode(&unmarshalled) + if err != nil { + return + } + }) +} diff --git a/operator/pkg/s3.go b/operator/pkg/s3.go index 157cd6674..4fb5d182e 100644 --- a/operator/pkg/s3.go +++ b/operator/pkg/s3.go @@ -8,7 +8,6 @@ import ( "time" "github.com/ugorji/go/codec" - "github.com/yetanotherco/aligned_layer/operator/merkle_tree" merkle_tree_old "github.com/yetanotherco/aligned_layer/operator/merkle_tree_old" ) @@ -105,13 +104,16 @@ func (o *Operator) getBatchFromDataService(ctx context.Context, batchURL string, var batch []VerificationData - decoder := codec.NewDecoderBytes(batchBytes, new(codec.CborHandle)) + decoder, err := createDecoderMode() + if err != nil { + return nil, fmt.Errorf("error creating CBOR decoder: %s", err) + } + err = decoder.Unmarshal(batchBytes, &batch) - err = decoder.Decode(&batch) if err != nil { o.Logger.Infof("Error decoding batch as CBOR: %s. Trying JSON decoding...", err) // try json - decoder = codec.NewDecoderBytes(batchBytes, new(codec.JsonHandle)) + decoder := codec.NewDecoderBytes(batchBytes, new(codec.JsonHandle)) err = decoder.Decode(&batch) if err != nil { return nil, err diff --git a/operator/pkg/valid_marshall_test.go b/operator/pkg/valid_marshall_test.go new file mode 100644 index 000000000..02bf4c498 --- /dev/null +++ b/operator/pkg/valid_marshall_test.go @@ -0,0 +1,32 @@ +package operator + +import ( + "bytes" + "testing" + + fuzz "github.com/AdaLogics/go-fuzz-headers" + "github.com/fxamacker/cbor/v2" +) + +// Test roundtrip of cbor serialization used in Aligned to check correctness. +func FuzzValidMarshall(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte, seed int64) { + fz := fuzz.NewConsumer(data) + var verification_data VerificationData + err := fz.GenerateStruct(&verification_data) + if err != nil { + return + } + + var marshalled []byte + encoder := cbor.NewEncoder(bytes.NewBuffer(marshalled)) + err = encoder.Encode(&verification_data) + if err != nil { + return + } + + if len(data) != 0 && !bytes.Equal(data, marshalled) { + t.Fatalf("data and marshalled are not equal. data[%d]: [%v], marshalled[%d]: [%s]", len(data), data, len(marshalled), marshalled) + } + }) +}