diff --git a/aws/kms/client.go b/aws/kms/client.go index 559e910a..3b24828e 100644 --- a/aws/kms/client.go +++ b/aws/kms/client.go @@ -2,8 +2,8 @@ package kms import ( "context" - "fmt" + "github.com/Layr-Labs/eigensdk-go/utils" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/kms" ) @@ -11,7 +11,7 @@ import ( func NewKMSClient(ctx context.Context, region string) (*kms.Client, error) { config, err := config.LoadDefaultConfig(ctx, config.WithRegion(region)) if err != nil { - return nil, fmt.Errorf("failed to load AWS config: %w", err) + return nil, utils.WrapError("failed to load AWS config", err) } c := kms.NewFromConfig(config) diff --git a/aws/kms/get_public_key.go b/aws/kms/get_public_key.go index 665a5b42..05cae1b1 100644 --- a/aws/kms/get_public_key.go +++ b/aws/kms/get_public_key.go @@ -6,6 +6,7 @@ import ( "encoding/asn1" "fmt" + "github.com/Layr-Labs/eigensdk-go/utils" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/kms" "github.com/ethereum/go-ethereum/crypto" @@ -28,18 +29,21 @@ func GetECDSAPublicKey(ctx context.Context, svc *kms.Client, keyId string) (*ecd KeyId: aws.String(keyId), }) if err != nil { - return nil, fmt.Errorf("failed to get public key for KeyId=%s: %w", keyId, err) + text := fmt.Sprintf("failed to get public key for KeyId=%s", keyId) + return nil, utils.WrapError(text, err) } var asn1pubk asn1EcPublicKey _, err = asn1.Unmarshal(getPubKeyOutput.PublicKey, &asn1pubk) if err != nil { - return nil, fmt.Errorf("failed to unmarshal public key for KeyId=%s: %w", keyId, err) + text := fmt.Sprintf("failed to unmarshal public key for KeyId=%s", keyId) + return nil, utils.WrapError(text, err) } pubkey, err := crypto.UnmarshalPubkey(asn1pubk.PublicKey.Bytes) if err != nil { - return nil, fmt.Errorf("failed to unmarshal public key for KeyId=%s: %w", keyId, err) + text := fmt.Sprintf("failed to unmarshal public key for KeyId=%s", keyId) + return nil, utils.WrapError(text, err) } return pubkey, nil diff --git a/chainio/clients/fireblocks/cancel_transaction.go b/chainio/clients/fireblocks/cancel_transaction.go index b59c23ee..93303f23 100644 --- a/chainio/clients/fireblocks/cancel_transaction.go +++ b/chainio/clients/fireblocks/cancel_transaction.go @@ -5,6 +5,8 @@ import ( "encoding/json" "fmt" "strings" + + "github.com/Layr-Labs/eigensdk-go/utils" ) type CancelTransactionResponse struct { @@ -16,12 +18,12 @@ func (f *client) CancelTransaction(ctx context.Context, txID string) (bool, erro path := fmt.Sprintf("/v1/transactions/%s/cancel", txID) res, err := f.makeRequest(ctx, "POST", path, nil) if err != nil { - return false, fmt.Errorf("error making request: %w", err) + return false, utils.WrapError("error making request", err) } var response CancelTransactionResponse err = json.NewDecoder(strings.NewReader(string(res))).Decode(&response) if err != nil { - return false, fmt.Errorf("error parsing response body: %w", err) + return false, utils.WrapError("error parsing response body", err) } return response.Success, nil diff --git a/chainio/clients/fireblocks/client.go b/chainio/clients/fireblocks/client.go index 6e52fd20..dfa4d266 100644 --- a/chainio/clients/fireblocks/client.go +++ b/chainio/clients/fireblocks/client.go @@ -14,6 +14,7 @@ import ( "time" "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/Layr-Labs/eigensdk-go/utils" "github.com/golang-jwt/jwt" "github.com/google/uuid" ) @@ -93,7 +94,7 @@ func NewClient( c := http.Client{Timeout: timeout} privateKey, err := jwt.ParseRSAPrivateKeyFromPEM(secretKey) if err != nil { - return nil, fmt.Errorf("error parsing RSA private key: %w", err) + return nil, utils.WrapError("error parsing RSA private key", err) } return &client{ @@ -116,7 +117,7 @@ func (f *client) signJwt(path string, bodyJson interface{}, durationSeconds int6 bodyBytes, err := json.Marshal(bodyJson) if err != nil { - return "", fmt.Errorf("error marshaling JSON: %w", err) + return "", utils.WrapError("error marshaling JSON", err) } h := sha256.New() @@ -135,7 +136,7 @@ func (f *client) signJwt(path string, bodyJson interface{}, durationSeconds int6 token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims) tokenString, err := token.SignedString(f.privateKey) if err != nil { - return "", fmt.Errorf("error signing token: %w", err) + return "", utils.WrapError("error signing token", err) } return tokenString, nil @@ -148,17 +149,18 @@ func (f *client) makeRequest(ctx context.Context, method, path string, body inte // remove query parameters from path and join with baseURL pathURI, err := url.Parse(path) if err != nil { - return nil, fmt.Errorf("error parsing URL: %w", err) + return nil, utils.WrapError("error parsing URL", err) } query := pathURI.Query() pathURI.RawQuery = "" urlStr, err := url.JoinPath(f.baseURL, pathURI.String()) if err != nil { - return nil, fmt.Errorf("error joining URL path with %s and %s: %w", f.baseURL, path, err) + text := fmt.Sprintf("error joining URL path with %s and %s", f.baseURL, path) + return nil, utils.WrapError(text, err) } url, err := url.Parse(urlStr) if err != nil { - return nil, fmt.Errorf("error parsing URL: %w", err) + return nil, utils.WrapError("error parsing URL", err) } // add query parameters back to path url.RawQuery = query.Encode() @@ -168,18 +170,18 @@ func (f *client) makeRequest(ctx context.Context, method, path string, body inte var err error reqBodyBytes, err = json.Marshal(body) if err != nil { - return nil, fmt.Errorf("error marshaling request body: %w", err) + return nil, utils.WrapError("error marshaling request body", err) } } token, err := f.signJwt(path, body, int64(f.timeout.Seconds())) if err != nil { - return nil, fmt.Errorf("error signing JWT: %w", err) + return nil, utils.WrapError("error signing JWT", err) } req, err := http.NewRequest(method, url.String(), bytes.NewBuffer(reqBodyBytes)) if err != nil { - return nil, fmt.Errorf("error creating HTTP request: %w", err) + return nil, utils.WrapError("error creating HTTP request", err) } if method == "POST" { @@ -191,27 +193,27 @@ func (f *client) makeRequest(ctx context.Context, method, path string, body inte resp, err := f.client.Do(req) if err != nil { - return nil, fmt.Errorf("error sending HTTP request: %w", err) + return nil, utils.WrapError("error sending HTTP request", err) } defer resp.Body.Close() respBody, err := io.ReadAll(resp.Body) if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) + return nil, utils.WrapError("error reading response body", err) } if resp.StatusCode != http.StatusOK { var errResp ErrorResponse err = json.Unmarshal(respBody, &errResp) if err != nil { - return nil, fmt.Errorf("error parsing error response: %w", err) + return nil, utils.WrapError("error parsing error response", err) } - return nil, fmt.Errorf( - "error response (%d) from Fireblocks with code %d: %s", + + text := fmt.Sprintf("error response (%d) from Fireblocks with code %d: %s", resp.StatusCode, errResp.Code, - errResp.Message, - ) + errResp.Message) + return nil, utils.WrapError(text, err) } return respBody, nil diff --git a/chainio/clients/fireblocks/contract_call.go b/chainio/clients/fireblocks/contract_call.go index 83e79245..cf9ae4af 100644 --- a/chainio/clients/fireblocks/contract_call.go +++ b/chainio/clients/fireblocks/contract_call.go @@ -3,8 +3,9 @@ package fireblocks import ( "context" "encoding/json" - "fmt" "strings" + + "github.com/Layr-Labs/eigensdk-go/utils" ) func NewContractCallRequest( @@ -58,12 +59,12 @@ func (f *client) ContractCall(ctx context.Context, req *TransactionRequest) (*Tr f.logger.Debug("Fireblocks call contract", "req", req) res, err := f.makeRequest(ctx, "POST", "/v1/transactions", req) if err != nil { - return nil, fmt.Errorf("error making request: %w", err) + return nil, utils.WrapError("error making request", err) } var response TransactionResponse err = json.NewDecoder(strings.NewReader(string(res))).Decode(&response) if err != nil { - return nil, fmt.Errorf("error parsing response body: %w", err) + return nil, utils.WrapError("error parsing response body", err) } return &TransactionResponse{ diff --git a/chainio/clients/fireblocks/get_asset_addresses.go b/chainio/clients/fireblocks/get_asset_addresses.go index e1a05281..35bb4188 100644 --- a/chainio/clients/fireblocks/get_asset_addresses.go +++ b/chainio/clients/fireblocks/get_asset_addresses.go @@ -6,6 +6,8 @@ import ( "fmt" "net/url" "strings" + + "github.com/Layr-Labs/eigensdk-go/utils" ) type AssetAddress struct { @@ -40,7 +42,7 @@ func (f *client) GetAssetAddresses(ctx context.Context, vaultID string, assetID path := fmt.Sprintf("/v1/vault/accounts/%s/%s/addresses_paginated", vaultID, assetID) u, err := url.Parse(path) if err != nil { - return addresses, fmt.Errorf("error parsing URL: %w", err) + return nil, utils.WrapError("error parsing URL", err) } q := u.Query() q.Set("before", p.Before) @@ -49,12 +51,13 @@ func (f *client) GetAssetAddresses(ctx context.Context, vaultID string, assetID res, err := f.makeRequest(ctx, "GET", u.String(), nil) if err != nil { - return nil, fmt.Errorf("error making request: %w", err) + return nil, utils.WrapError("error making request", err) } body := string(res) err = json.NewDecoder(strings.NewReader(body)).Decode(&response) if err != nil { - return addresses, fmt.Errorf("error parsing response body: %s: %w", body, err) + text := fmt.Sprintf("error parsing response body: %s", body) + return nil, utils.WrapError(text, err) } addresses = append(addresses, response.Addresses...) diff --git a/chainio/clients/fireblocks/get_transaction.go b/chainio/clients/fireblocks/get_transaction.go index cd2221a6..256b5a3c 100644 --- a/chainio/clients/fireblocks/get_transaction.go +++ b/chainio/clients/fireblocks/get_transaction.go @@ -5,6 +5,8 @@ import ( "encoding/json" "fmt" "strings" + + "github.com/Layr-Labs/eigensdk-go/utils" ) // Transaction is a type for the transaction response from Fireblocks @@ -52,12 +54,12 @@ func (f *client) GetTransaction(ctx context.Context, txID string) (*Transaction, path := fmt.Sprintf("/v1/transactions/%s", txID) res, err := f.makeRequest(ctx, "GET", path, nil) if err != nil { - return nil, fmt.Errorf("error making request: %w", err) + return nil, utils.WrapError("error making request", err) } var tx Transaction err = json.NewDecoder(strings.NewReader(string(res))).Decode(&tx) if err != nil { - return nil, fmt.Errorf("error parsing response body: %w", err) + return nil, utils.WrapError("error parsing response body", err) } return &tx, nil diff --git a/chainio/clients/fireblocks/list_contracts.go b/chainio/clients/fireblocks/list_contracts.go index a964bd6b..54bfe1bc 100644 --- a/chainio/clients/fireblocks/list_contracts.go +++ b/chainio/clients/fireblocks/list_contracts.go @@ -6,6 +6,7 @@ import ( "fmt" "strings" + "github.com/Layr-Labs/eigensdk-go/utils" "github.com/ethereum/go-ethereum/common" ) @@ -24,12 +25,13 @@ func (f *client) ListContracts(ctx context.Context) ([]WhitelistedContract, erro var contracts []WhitelistedContract res, err := f.makeRequest(ctx, "GET", "/v1/contracts", nil) if err != nil { - return contracts, fmt.Errorf("error making request: %w", err) + return contracts, utils.WrapError("error making request", err) } body := string(res) err = json.NewDecoder(strings.NewReader(body)).Decode(&contracts) if err != nil { - return contracts, fmt.Errorf("error parsing response body: %s: %w", body, err) + text := fmt.Sprintf("error parsing response body: %s", body) + return contracts, utils.WrapError(text, err) } return contracts, nil diff --git a/chainio/clients/fireblocks/list_external_accounts.go b/chainio/clients/fireblocks/list_external_accounts.go index ac3715ea..46381fcb 100644 --- a/chainio/clients/fireblocks/list_external_accounts.go +++ b/chainio/clients/fireblocks/list_external_accounts.go @@ -6,6 +6,7 @@ import ( "fmt" "strings" + "github.com/Layr-Labs/eigensdk-go/utils" "github.com/ethereum/go-ethereum/common" ) @@ -26,12 +27,13 @@ func (f *client) ListExternalWallets(ctx context.Context) ([]WhitelistedAccount, var accounts []WhitelistedAccount res, err := f.makeRequest(ctx, "GET", "/v1/external_wallets", nil) if err != nil { - return accounts, fmt.Errorf("error making request: %w", err) + return accounts, utils.WrapError("error making request", err) } body := string(res) err = json.NewDecoder(strings.NewReader(body)).Decode(&accounts) if err != nil { - return accounts, fmt.Errorf("error parsing response body: %s: %w", body, err) + text := fmt.Sprintf("error parsing response body: %s", body) + return accounts, utils.WrapError(text, err) } return accounts, nil diff --git a/chainio/clients/fireblocks/list_vault_accounts.go b/chainio/clients/fireblocks/list_vault_accounts.go index 068d5ab1..99bf9250 100644 --- a/chainio/clients/fireblocks/list_vault_accounts.go +++ b/chainio/clients/fireblocks/list_vault_accounts.go @@ -6,6 +6,8 @@ import ( "fmt" "net/url" "strings" + + "github.com/Layr-Labs/eigensdk-go/utils" ) type Asset struct { @@ -36,7 +38,7 @@ func (f *client) ListVaultAccounts(ctx context.Context) ([]VaultAccount, error) for next { u, err := url.Parse("/v1/vault/accounts_paged") if err != nil { - return accounts, fmt.Errorf("error parsing URL: %w", err) + return accounts, utils.WrapError("error parsing URL", err) } q := u.Query() q.Set("before", p.Before) @@ -44,12 +46,13 @@ func (f *client) ListVaultAccounts(ctx context.Context) ([]VaultAccount, error) u.RawQuery = q.Encode() res, err := f.makeRequest(ctx, "GET", u.String(), nil) if err != nil { - return accounts, fmt.Errorf("error making request: %w", err) + return accounts, utils.WrapError("error making request", err) } body := string(res) err = json.NewDecoder(strings.NewReader(body)).Decode(&response) if err != nil { - return accounts, fmt.Errorf("error parsing response body: %s: %w", body, err) + text := fmt.Sprintf("error parsing response body: %s", body) + return accounts, utils.WrapError(text, err) } accounts = append(accounts, response.Accounts...) diff --git a/chainio/clients/fireblocks/transfer.go b/chainio/clients/fireblocks/transfer.go index a1f70d22..801d2572 100644 --- a/chainio/clients/fireblocks/transfer.go +++ b/chainio/clients/fireblocks/transfer.go @@ -3,8 +3,9 @@ package fireblocks import ( "context" "encoding/json" - "fmt" "strings" + + "github.com/Layr-Labs/eigensdk-go/utils" ) func NewTransferRequest( @@ -54,12 +55,12 @@ func (f *client) Transfer(ctx context.Context, req *TransactionRequest) (*Transa f.logger.Debug("Fireblocks transfer", "req", req) res, err := f.makeRequest(ctx, "POST", "/v1/transactions", req) if err != nil { - return nil, fmt.Errorf("error making request: %w", err) + return nil, utils.WrapError("error making request", err) } var response TransactionResponse err = json.NewDecoder(strings.NewReader(string(res))).Decode(&response) if err != nil { - return nil, fmt.Errorf("error parsing response body: %w", err) + return nil, utils.WrapError("error parsing response body", err) } return &TransactionResponse{ diff --git a/chainio/clients/wallet/fireblocks_wallet.go b/chainio/clients/wallet/fireblocks_wallet.go index ea8a9f1e..ec3ac996 100644 --- a/chainio/clients/wallet/fireblocks_wallet.go +++ b/chainio/clients/wallet/fireblocks_wallet.go @@ -12,6 +12,7 @@ import ( "github.com/Layr-Labs/eigensdk-go/chainio/clients/fireblocks" "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/Layr-Labs/eigensdk-go/utils" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" @@ -71,7 +72,7 @@ func NewFireblocksWallet( ) (Wallet, error) { chainID, err := ethClient.ChainID(context.Background()) if err != nil { - return nil, fmt.Errorf("error getting chain ID: %w", err) + return nil, utils.WrapError("error getting chain ID", err) } logger.Debug("Creating new Fireblocks wallet for chain", "chainID", chainID) return &fireblocksWallet{ @@ -95,7 +96,7 @@ func (t *fireblocksWallet) getAccount(ctx context.Context) (*fireblocks.VaultAcc if t.account == nil { accounts, err := t.fireblocksClient.ListVaultAccounts(ctx) if err != nil { - return nil, fmt.Errorf("error listing vault accounts: %w", err) + return nil, utils.WrapError("error listing vault accounts", err) } for i, a := range accounts { if a.Name == t.vaultAccountName { @@ -119,7 +120,7 @@ func (f *fireblocksWallet) getWhitelistedAccount( if !ok { accounts, err := f.fireblocksClient.ListExternalWallets(ctx) if err != nil { - return nil, fmt.Errorf("error listing external wallets: %w", err) + return nil, utils.WrapError("error listing external wallets", err) } for i, a := range accounts { for _, asset := range a.Assets { @@ -150,7 +151,7 @@ func (t *fireblocksWallet) getWhitelistedContract( if !ok { contracts, err := t.fireblocksClient.ListContracts(ctx) if err != nil { - return nil, fmt.Errorf("error listing contracts: %w", err) + return nil, utils.WrapError("error listing contracts", err) } for i_c, c := range contracts { for _, a := range c.Assets { @@ -176,7 +177,7 @@ func (t *fireblocksWallet) SendTransaction(ctx context.Context, tx *types.Transa } account, err := t.getAccount(ctx) if err != nil { - return "", fmt.Errorf("error getting account: %w", err) + return "", utils.WrapError("error getting account:", err) } foundAsset := false for _, a := range account.Assets { @@ -201,7 +202,8 @@ func (t *fireblocksWallet) SendTransaction(ctx context.Context, tx *types.Transa if txID, ok := t.nonceToTxID[nonce]; ok { fireblockTx, err := t.fireblocksClient.GetTransaction(ctx, txID) if err != nil { - return "", fmt.Errorf("error getting fireblocks transaction %s: %w", txID, err) + text := fmt.Sprintf("error getting fireblocks transaction %s", txID) + return "", utils.WrapError(text, err) } if fireblockTx.TxHash != "" { replaceTxByHash = fireblockTx.TxHash @@ -273,7 +275,8 @@ func (t *fireblocksWallet) SendTransaction(ctx context.Context, tx *types.Transa } if err != nil { - return "", fmt.Errorf("error sending a transaction %s: %w", tx.To().Hex(), err) + text := fmt.Sprintf("error sending a transaction %s", tx.To().Hex()) + return "", utils.WrapError(text, err) } t.nonceToTxID[nonce] = res.ID t.txIDToNonce[res.ID] = nonce @@ -289,7 +292,8 @@ func (t *fireblocksWallet) CancelTransactionBroadcast(ctx context.Context, txID func (t *fireblocksWallet) GetTransactionReceipt(ctx context.Context, txID TxID) (*types.Receipt, error) { fireblockTx, err := t.fireblocksClient.GetTransaction(ctx, txID) if err != nil { - return nil, fmt.Errorf("error getting fireblocks transaction %s: %w", txID, err) + text := fmt.Sprintf("error getting fireblocks transaction %s", txID) + return nil, utils.WrapError(text, err) } if fireblockTx.Status == fireblocks.Completed { txHash := common.HexToHash(fireblockTx.TxHash) @@ -307,7 +311,7 @@ func (t *fireblocksWallet) GetTransactionReceipt(ctx context.Context, txID TxID) if errors.Is(err, ethereum.NotFound) { return nil, fmt.Errorf("%w: for txID %s", ErrReceiptNotYetAvailable, txID) } else { - return nil, fmt.Errorf("Transaction receipt retrieval failed: %w", err) + return nil, utils.WrapError("Transaction receipt retrieval failed", err) } } else if fireblockTx.Status == fireblocks.Failed || fireblockTx.Status == fireblocks.Rejected || @@ -336,7 +340,7 @@ func (t *fireblocksWallet) GetTransactionReceipt(ctx context.Context, txID TxID) func (f *fireblocksWallet) SenderAddress(ctx context.Context) (common.Address, error) { account, err := f.getAccount(ctx) if err != nil { - return common.Address{}, fmt.Errorf("error getting account: %w", err) + return common.Address{}, utils.WrapError("error getting account", err) } addresses, err := f.fireblocksClient.GetAssetAddresses( ctx, @@ -344,7 +348,7 @@ func (f *fireblocksWallet) SenderAddress(ctx context.Context) (common.Address, e fireblocks.AssetIDByChain[f.chainID.Uint64()], ) if err != nil { - return common.Address{}, fmt.Errorf("error getting asset addresses: %w", err) + return common.Address{}, utils.WrapError("error getting asset addresses", err) } if len(addresses) == 0 { return common.Address{}, errors.New("no addresses found") diff --git a/chainio/clients/wallet/privatekey_wallet.go b/chainio/clients/wallet/privatekey_wallet.go index f98a4225..64dfb176 100644 --- a/chainio/clients/wallet/privatekey_wallet.go +++ b/chainio/clients/wallet/privatekey_wallet.go @@ -50,12 +50,14 @@ func (t *privateKeyWallet) SendTransaction(ctx context.Context, tx *types.Transa t.logger.Debug("Sending transaction") signedTx, err := signer(t.address, tx) if err != nil { - return "", utils.WrapError(fmt.Errorf("sign: tx %v failed.", tx.Hash().String()), err) + text := fmt.Sprintf("sign: tx %v failed.", tx.Hash().String()) + return "", utils.WrapError(text, err) } err = t.ethClient.SendTransaction(ctx, signedTx) if err != nil { - return "", utils.WrapError(fmt.Errorf("send: tx %v failed.", tx.Hash().String()), err) + text := fmt.Sprintf("send: tx %v failed.", tx.Hash().String()) + return "", utils.WrapError(text, err) } return signedTx.Hash().Hex(), nil diff --git a/chainio/txmgr/geometric/geometric.go b/chainio/txmgr/geometric/geometric.go index f7c9627d..636afa61 100644 --- a/chainio/txmgr/geometric/geometric.go +++ b/chainio/txmgr/geometric/geometric.go @@ -233,7 +233,8 @@ func (t *GeometricTxManager) processTransaction(ctx context.Context, req *txnReq retryFromFailure++ continue } else if err != nil { - return nil, utils.WrapError(fmt.Errorf("failed to send txn %s", txn.Hash().Hex()), err) + text := fmt.Sprintf("failed to send txn %s", txn.Hash().Hex()) + return nil, utils.WrapError(text, err) } else { t.logger.Debug("successfully sent txn", "txID", txID, "txHash", txn.Hash().Hex()) break @@ -241,7 +242,8 @@ func (t *GeometricTxManager) processTransaction(ctx context.Context, req *txnReq } // if all attempts to send the tx failed, return an error if txn == nil || txID == "" { - return nil, utils.WrapError(fmt.Errorf("failed to send txn %s", req.tx.Hash().Hex()), err) + text := fmt.Sprintf("failed to send txn %s", req.tx.Hash().Hex()) + return nil, utils.WrapError(text, err) } req.tx = txn diff --git a/crypto/ecdsa/utils.go b/crypto/ecdsa/utils.go index e8107ee6..7ff05d68 100644 --- a/crypto/ecdsa/utils.go +++ b/crypto/ecdsa/utils.go @@ -9,6 +9,7 @@ import ( "path/filepath" "strings" + "github.com/Layr-Labs/eigensdk-go/utils" "github.com/ethereum/go-ethereum/common" gethcommon "github.com/ethereum/go-ethereum/common" @@ -120,7 +121,8 @@ func KeyAndAddressFromHexKey(hexkey string) (*ecdsa.PrivateKey, common.Address, hexkey = strings.TrimPrefix(hexkey, "0x") ecdsaSk, err := crypto.HexToECDSA(hexkey) if err != nil { - return nil, common.Address{}, fmt.Errorf("failed to convert hexkey %s to ecdsa key: %w", hexkey, err) + text := fmt.Sprintf("failed to convert hexkey %s to ecdsa key", hexkey) + return nil, common.Address{}, utils.WrapError(text, err) } pk := ecdsaSk.Public() address := crypto.PubkeyToAddress(*pk.(*ecdsa.PublicKey)) diff --git a/crypto/utils/batch_key.go b/crypto/utils/batch_key.go index c8c8673d..573d6777 100644 --- a/crypto/utils/batch_key.go +++ b/crypto/utils/batch_key.go @@ -5,6 +5,8 @@ import ( "fmt" "os" "path/filepath" + + "github.com/Layr-Labs/eigensdk-go/utils" ) const ( @@ -34,7 +36,7 @@ func ReadBatchKeys(folder string, isECDSA bool) ([]BatchKey, error) { defer func(privateKeyFile *os.File) { err := privateKeyFile.Close() if err != nil { - _ = fmt.Errorf("error closing the file: %s", err) + _ = utils.WrapError("error closing the file", err) return } }(privateKeyFile) @@ -43,12 +45,12 @@ func ReadBatchKeys(folder string, isECDSA bool) ([]BatchKey, error) { passwordFile, err := os.Open(filepath.Clean(absFolder + "/" + PasswordFile)) if err != nil { fmt.Println("Error opening the file:", err) - return nil, err + return nil, utils.WrapError("error opening the file", err) } defer func(passwordFile *os.File) { err := passwordFile.Close() if err != nil { - _ = fmt.Errorf("error closing the file: %s", err) + _ = utils.WrapError("error closing the file", err) return } }(passwordFile) diff --git a/services/bls_aggregation/blsagg.go b/services/bls_aggregation/blsagg.go index 4c22d1e8..881b1ce9 100644 --- a/services/bls_aggregation/blsagg.go +++ b/services/bls_aggregation/blsagg.go @@ -22,7 +22,8 @@ var ( // error string directly. // see https://go.dev/blog/go1.13-errors TaskInitializationErrorFn = func(err error, taskIndex types.TaskIndex) error { - return fmt.Errorf("Failed to initialize task %d: %w", taskIndex, err) + text := fmt.Sprintf("Failed to initialize task %d", taskIndex) + return utils.WrapError(text, err) } TaskAlreadyInitializedErrorFn = func(taskIndex types.TaskIndex) error { return fmt.Errorf("task %d already initialized", taskIndex) @@ -37,12 +38,12 @@ var ( return fmt.Errorf("operator %x not part of task %d's quorum", operatorId, taskIndex) } HashFunctionError = func(err error) error { - return fmt.Errorf("Failed to hash task response: %w", err) + return utils.WrapError("Failed to hash task response", err) } SignatureVerificationError = func(err error) error { - return fmt.Errorf("Failed to verify signature: %w", err) + return utils.WrapError("Failed to verify signature", err) } - IncorrectSignatureError = errors.New("Signature verification failed. Incorrect Signature.") + ErrIncorrectSignature = errors.New("signature verification failed. Incorrect Signature") ) // BlsAggregationServiceResponse is the response from the bls aggregation service @@ -349,8 +350,12 @@ func (a *BlsAggregatorService) singleTaskAggregatorGoroutineFunc( "err", err, ) + text := fmt.Sprintf( + "AggregatorService failed to get operators state from avs registry at blockNum %d", + taskCreatedBlock, + ) a.aggregatedResponsesC <- BlsAggregationServiceResponse{ - Err: TaskInitializationErrorFn(fmt.Errorf("AggregatorService failed to get operators state from avs registry at blockNum %d: %w", taskCreatedBlock, err), taskIndex), + Err: TaskInitializationErrorFn(utils.WrapError(text, err), taskIndex), TaskIndex: taskIndex, } return @@ -369,7 +374,7 @@ func (a *BlsAggregatorService) singleTaskAggregatorGoroutineFunc( err, ) a.aggregatedResponsesC <- BlsAggregationServiceResponse{ - Err: TaskInitializationErrorFn(fmt.Errorf("Aggregator failed to get quorums state from avs registry: %w", err), taskIndex), + Err: TaskInitializationErrorFn(utils.WrapError("Aggregator failed to get quorums state from avs registry", err), taskIndex), TaskIndex: taskIndex, } return @@ -659,7 +664,7 @@ func (a *BlsAggregatorService) verifySignature( return SignatureVerificationError(err) } if !signatureVerified { - return IncorrectSignatureError + return ErrIncorrectSignature } return nil } diff --git a/services/bls_aggregation/blsagg_test.go b/services/bls_aggregation/blsagg_test.go index 5e3d0425..46602f7d 100644 --- a/services/bls_aggregation/blsagg_test.go +++ b/services/bls_aggregation/blsagg_test.go @@ -1185,7 +1185,7 @@ func TestBlsAgg(t *testing.T) { blsSig, testOperator1.OperatorId, ) - require.EqualError(t, err, "Signature verification failed. Incorrect Signature.") + require.EqualError(t, err, "signature verification failed. Incorrect Signature") }, ) diff --git a/signer/bls/cerberus/cerberus.go b/signer/bls/cerberus/cerberus.go index c8b87db8..bafe474c 100644 --- a/signer/bls/cerberus/cerberus.go +++ b/signer/bls/cerberus/cerberus.go @@ -3,7 +3,6 @@ package cerberus import ( "context" "encoding/hex" - "fmt" "time" "google.golang.org/grpc" @@ -12,6 +11,7 @@ import ( sdkBls "github.com/Layr-Labs/eigensdk-go/crypto/bls" "github.com/Layr-Labs/eigensdk-go/signer/bls/types" + "github.com/Layr-Labs/eigensdk-go/utils" "github.com/consensys/gnark-crypto/ecc/bn254" v1 "github.com/Layr-Labs/cerberus-api/pkg/api/v1" @@ -42,7 +42,7 @@ func New(cfg Config) (Signer, error) { if cfg.EnableTLS { creds, err := credentials.NewClientTLSFromFile(cfg.TLSCertFilePath, "") if err != nil { - return Signer{}, fmt.Errorf("could not load tls cert: %w", err) + return Signer{}, utils.WrapError("could not load tls cert", err) } opts = append(opts, grpc.WithTransportCredentials(creds)) } else { @@ -51,7 +51,7 @@ func New(cfg Config) (Signer, error) { conn, err := grpc.NewClient(cfg.URL, opts...) if err != nil { - return Signer{}, fmt.Errorf("did not connect: %w", err) + return Signer{}, utils.WrapError("did not connect", err) } signerClient := v1.NewSignerClient(conn) @@ -101,12 +101,12 @@ func (s Signer) SignG1(ctx context.Context, msg []byte) ([]byte, error) { func (s Signer) GetOperatorId() (string, error) { pkBytes, err := hex.DecodeString(s.pubKeyHex) if err != nil { - return "", fmt.Errorf("failed to decode BLS public key: %w", err) + return "", utils.WrapError("failed to decode BLS public key", err) } var point bn254.G1Affine _, err = point.SetBytes(pkBytes) if err != nil { - return "", fmt.Errorf("failed to set BLS public key: %w", err) + return "", utils.WrapError("failed to set BLS public key", err) } pubkey := &sdkBls.G1Point{G1Affine: &point} return pubkey.GetOperatorID(), nil diff --git a/signerv2/kms_signer_test.go b/signerv2/kms_signer_test.go index 8dd09124..b5613d91 100644 --- a/signerv2/kms_signer_test.go +++ b/signerv2/kms_signer_test.go @@ -12,6 +12,7 @@ import ( "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" "github.com/Layr-Labs/eigensdk-go/signerv2" "github.com/Layr-Labs/eigensdk-go/testutils" + "github.com/Layr-Labs/eigensdk-go/utils" "github.com/aws/aws-sdk-go-v2/service/kms/types" @@ -51,30 +52,30 @@ func setup() error { var err error localstack, err = testutils.StartLocalstackContainer("kms_signer_test") if err != nil { - return fmt.Errorf("failed to start Localstack container: %w", err) + return utils.WrapError("failed to start Localstack container", err) } mappedPort, err := localstack.MappedPort(context.Background(), testutils.LocalStackPort) if err != nil { - return fmt.Errorf("failed to get mapped port: %w", err) + return utils.WrapError("failed to get mapped port", err) } mappedLocalstackPort = string(mappedPort) anvil, err = testutils.StartAnvilContainer("") if err != nil { - return fmt.Errorf("failed to start Anvil container: %w", err) + return utils.WrapError("failed to start Anvil container", err) } endpoint, err := anvil.Endpoint(context.Background(), "") if err != nil { - return fmt.Errorf("failed to get Anvil endpoint: %w", err) + return utils.WrapError("failed to get Anvil endpoint", err) } anvilEndpoint = fmt.Sprintf("http://%s", endpoint) rpcClient, err = rpc.Dial(anvilEndpoint) if err != nil { - return fmt.Errorf("failed to dial Anvil RPC: %w", err) + return utils.WrapError("failed to dial Anvil RPC", err) } keyMetadata, err = testutils.CreateKMSKey(mappedLocalstackPort) if err != nil { - return fmt.Errorf("failed to create KMS key: %w", err) + return utils.WrapError("failed to create KMS key", err) } return nil } diff --git a/testutils/localstack.go b/testutils/localstack.go index bf3722df..1c2688fc 100644 --- a/testutils/localstack.go +++ b/testutils/localstack.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/Layr-Labs/eigensdk-go/aws" + "github.com/Layr-Labs/eigensdk-go/utils" "github.com/aws/aws-sdk-go-v2/service/kms" "github.com/aws/aws-sdk-go-v2/service/kms/types" "github.com/testcontainers/testcontainers-go" @@ -39,7 +40,7 @@ func NewKMSClient(localStackPort string) (*kms.Client, error) { fmt.Sprintf("http://127.0.0.1:%s", localStackPort), ) if err != nil { - return nil, fmt.Errorf("failed to load AWS config: %w", err) + return nil, utils.WrapError("failed to load AWS config", err) } c := kms.NewFromConfig(*cfg) @@ -49,14 +50,14 @@ func NewKMSClient(localStackPort string) (*kms.Client, error) { func CreateKMSKey(localStackPort string) (*types.KeyMetadata, error) { c, err := NewKMSClient(localStackPort) if err != nil { - return nil, fmt.Errorf("failed to create KMS client: %w", err) + return nil, utils.WrapError("failed to create KMS client", err) } res, err := c.CreateKey(context.Background(), &kms.CreateKeyInput{ KeySpec: types.KeySpecEccSecgP256k1, KeyUsage: types.KeyUsageTypeSignVerify, }) if err != nil { - return nil, fmt.Errorf("failed to create key: %w", err) + return nil, utils.WrapError("failed to create key", err) } return res.KeyMetadata, nil }