Skip to content

chore: use errors.New to replace fmt.Errorf with no parameters #1896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions prover/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
_ "embed"
"encoding/json"
"errors"
"fmt"
"io"
"light/light-prover/logging"
Expand Down Expand Up @@ -65,28 +66,28 @@ func runCli() {
batchAddressAppendBatchSize := uint32(context.Uint("address-append-batch-size"))

if (inclusionTreeHeight == 0 || inclusionNumberOfCompressedAccounts == 0) && circuit == prover.InclusionCircuitType {
return fmt.Errorf("inclusion tree height and number of compressed accounts must be provided")
return errors.New("inclusion tree height and number of compressed accounts must be provided")
}

if (nonInclusionTreeHeight == 0 || nonInclusionNumberOfCompressedAccounts == 0) && circuit == prover.NonInclusionCircuitType {
return fmt.Errorf("non-inclusion tree height and number of compressed accounts must be provided")
return errors.New("non-inclusion tree height and number of compressed accounts must be provided")
}

if circuit == prover.CombinedCircuitType {
if inclusionTreeHeight == 0 || inclusionNumberOfCompressedAccounts == 0 {
return fmt.Errorf("inclusion tree height and number of compressed accounts must be provided")
return errors.New("inclusion tree height and number of compressed accounts must be provided")
}
if nonInclusionTreeHeight == 0 || nonInclusionNumberOfCompressedAccounts == 0 {
return fmt.Errorf("non-inclusion tree height and number of compressed accounts must be provided")
return errors.New("non-inclusion tree height and number of compressed accounts must be provided")
}
}

if (batchUpdateTreeHeight == 0 || batchUpdateBatchSize == 0) && circuit == prover.BatchUpdateCircuitType {
return fmt.Errorf("[Batch update]: tree height and batch size must be provided")
return errors.New("[Batch update]: tree height and batch size must be provided")
}

if (batchAddressAppendTreeHeight == 0 || batchAddressAppendBatchSize == 0) && circuit == prover.BatchAddressAppendCircuitType {
return fmt.Errorf("[Batch address append]: tree height and batch size must be provided")
return errors.New("[Batch address append]: tree height and batch size must be provided")
}

logging.Logger().Info().Msg("Running setup")
Expand Down Expand Up @@ -168,28 +169,28 @@ func runCli() {
batchAddressAppendBatchSize := uint32(context.Uint("address-append-batch-size"))

if (inclusionTreeHeight == 0 || inclusionNumberOfCompressedAccounts == 0) && circuit == "inclusion" {
return fmt.Errorf("[Inclusion]: tree height and number of compressed accounts must be provided")
return errors.New("[Inclusion]: tree height and number of compressed accounts must be provided")
}

if (nonInclusionTreeHeight == 0 || nonInclusionNumberOfCompressedAccounts == 0) && circuit == "non-inclusion" {
return fmt.Errorf("[Non-inclusion]: tree height and number of compressed accounts must be provided")
return errors.New("[Non-inclusion]: tree height and number of compressed accounts must be provided")
}

if circuit == "combined" {
if inclusionTreeHeight == 0 || inclusionNumberOfCompressedAccounts == 0 {
return fmt.Errorf("[Combined]: tree height and number of compressed accounts must be provided")
return errors.New("[Combined]: tree height and number of compressed accounts must be provided")
}
if nonInclusionTreeHeight == 0 || nonInclusionNumberOfCompressedAccounts == 0 {
return fmt.Errorf("[Combined]: tree height and number of compressed accounts must be provided")
return errors.New("[Combined]: tree height and number of compressed accounts must be provided")
}
}

if (batchUpdateTreeHeight == 0 || batchUpdateBatchSize == 0) && circuit == prover.BatchUpdateCircuitType {
return fmt.Errorf("[Batch update]: tree height and batch size must be provided")
return errors.New("[Batch update]: tree height and batch size must be provided")
}

if (batchAddressAppendTreeHeight == 0 || batchAddressAppendBatchSize == 0) && circuit == prover.BatchAddressAppendCircuitType {
return fmt.Errorf("[Batch address append]: tree height and batch size must be provided")
return errors.New("[Batch address append]: tree height and batch size must be provided")
}

logging.Logger().Info().Msg("Building R1CS")
Expand Down Expand Up @@ -274,7 +275,7 @@ func runCli() {

if circuit == "append" {
if batchAppendTreeHeight == 0 || batchAppendBatchSize == 0 {
return fmt.Errorf("append tree height and batch size must be provided")
return errors.New("append tree height and batch size must be provided")
}
var system *prover.ProvingSystemV2
system, err = prover.ImportBatchAppendSetup(batchAppendTreeHeight, batchAppendBatchSize, pk, vk)
Expand All @@ -284,7 +285,7 @@ func runCli() {
err = prover.WriteProvingSystem(system, path, "")
} else if circuit == "update" {
if batchUpdateTreeHeight == 0 || batchUpdateBatchSize == 0 {
return fmt.Errorf("append tree height and batch size must be provided")
return errors.New("append tree height and batch size must be provided")
}
var system *prover.ProvingSystemV2
system, err = prover.ImportBatchUpdateSetup(batchUpdateTreeHeight, batchUpdateBatchSize, pk, vk)
Expand All @@ -294,7 +295,7 @@ func runCli() {
err = prover.WriteProvingSystem(system, path, "")
} else if circuit == "address-append" {
if batchAddressAppendTreeHeight == 0 || batchAddressAppendBatchSize == 0 {
return fmt.Errorf("append tree height and batch size must be provided")
return errors.New("append tree height and batch size must be provided")
}
var system *prover.ProvingSystemV2
system, err = prover.ImportBatchAddressAppendSetup(batchAddressAppendTreeHeight, batchAddressAppendBatchSize, pk, vk)
Expand All @@ -305,12 +306,12 @@ func runCli() {
} else {
if circuit == "inclusion" || circuit == "combined" {
if inclusionTreeHeight == 0 || inclusionNumberOfCompressedAccounts == 0 {
return fmt.Errorf("inclusion tree height and number of compressed accounts must be provided")
return errors.New("inclusion tree height and number of compressed accounts must be provided")
}
}
if circuit == "non-inclusion" || circuit == "combined" {
if nonInclusionTreeHeight == 0 || nonInclusionNumberOfCompressedAccounts == 0 {
return fmt.Errorf("non-inclusion tree height and number of compressed accounts must be provided")
return errors.New("non-inclusion tree height and number of compressed accounts must be provided")
}
}

Expand Down Expand Up @@ -359,7 +360,7 @@ func runCli() {
case *prover.ProvingSystemV2:
vk = s.VerifyingKey
default:
return fmt.Errorf("unknown proving system type")
return errors.New("unknown proving system type")
}

var buf bytes.Buffer
Expand Down Expand Up @@ -466,7 +467,7 @@ func runCli() {
}

if len(psv1) == 0 && len(psv2) == 0 {
return fmt.Errorf("no proving systems loaded")
return errors.New("no proving systems loaded")
}

redisURL := context.String("redis-url")
Expand Down Expand Up @@ -499,7 +500,7 @@ func runCli() {

if enableQueue {
if redisURL == "" {
return fmt.Errorf("Redis URL is required for queue mode. Use --redis-url or set REDIS_URL environment variable")
return errors.New("Redis URL is required for queue mode. Use --redis-url or set REDIS_URL environment variable")
}

redisQueue, err = server.NewRedisQueue(redisURL)
Expand Down Expand Up @@ -580,7 +581,7 @@ func runCli() {
}

if !enableServer && !enableQueue {
return fmt.Errorf("at least one of server or queue mode must be enabled")
return errors.New("at least one of server or queue mode must be enabled")
}

sigint := make(chan os.Signal, 1)
Expand Down Expand Up @@ -652,7 +653,7 @@ func runCli() {
}

if len(psv1) == 0 && len(psv2) == 0 {
return fmt.Errorf("no proving systems loaded")
return errors.New("no proving systems loaded")
}

logging.Logger().Info().Msg("Reading params from stdin")
Expand Down Expand Up @@ -836,7 +837,7 @@ func runCli() {
return fmt.Errorf("invalid circuit type for ProvingSystemV1: %s", circuit)
}
default:
return fmt.Errorf("unknown proving system type")
return errors.New("unknown proving system type")
}

if verifyErr != nil {
Expand Down
3 changes: 2 additions & 1 deletion prover/server/merkle-tree/indexed_merkle_tree.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package merkle_tree

import (
"errors"
"fmt"
"math/big"

Expand Down Expand Up @@ -102,7 +103,7 @@ func (imt *IndexedMerkleTree) Append(value *big.Int) error {
lowElement := imt.IndexArray.Get(lowElementIndex)

if value.Cmp(lowElement.NextValue) >= 0 {
return fmt.Errorf("new value must be less than next element value")
return errors.New("new value must be less than next element value")
}

newElementIndex := uint32(len(imt.IndexArray.Elements))
Expand Down
5 changes: 3 additions & 2 deletions prover/server/prover/batch_address_append_circuit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package prover

import (
"errors"
"fmt"
"light/light-prover/logging"
"light/light-prover/prover/poseidon"
Expand Down Expand Up @@ -138,10 +139,10 @@ func InitBatchAddressTreeAppendCircuit(treeHeight uint32, batchSize uint32) Batc

func (params *BatchAddressAppendParameters) CreateWitness() (*BatchAddressTreeAppendCircuit, error) {
if params.BatchSize == 0 {
return nil, fmt.Errorf("batch size cannot be 0")
return nil, errors.New("batch size cannot be 0")
}
if params.TreeHeight == 0 {
return nil, fmt.Errorf("tree height cannot be 0")
return nil, errors.New("tree height cannot be 0")
}

circuit := &BatchAddressTreeAppendCircuit{
Expand Down
3 changes: 2 additions & 1 deletion prover/server/prover/circuit_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package prover

import (
"encoding/json"
"errors"
"fmt"
)

Expand Down Expand Up @@ -88,7 +89,7 @@ func ParseProofRequestMeta(data []byte) (ProofRequestMeta, error) {
}

if addressTreeHeight == 0 && stateTreeHeight == 0 && treeHeight == 0 {
return ProofRequestMeta{}, fmt.Errorf("no 'addressTreeHeight' or stateTreeHeight'or 'treeHeight' provided")
return ProofRequestMeta{}, errors.New("no 'addressTreeHeight' or stateTreeHeight'or 'treeHeight' provided")
}

version := uint32(0)
Expand Down
7 changes: 4 additions & 3 deletions prover/server/prover/proving_keys_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package prover

import (
"bytes"
"errors"
"fmt"
"io"
"light/light-prover/logging"
Expand Down Expand Up @@ -81,7 +82,7 @@ func LoadVerifyingKey(filepath string) (verifyingKey groth16.VerifyingKey, err e
f, _ := os.Open(filepath)
_, err = verifyingKey.ReadFrom(f)
if err != nil {
return verifyingKey, fmt.Errorf("read file error")
return verifyingKey, errors.New("read file error")
}
err = f.Close()
if err != nil {
Expand Down Expand Up @@ -284,7 +285,7 @@ func LoadKeys(keysDirPath string, runMode RunMode, circuits []string) ([]*Provin
Uint32("batchSize", s.BatchSize).
Msg("Read ProvingSystemV2")
default:
return nil, nil, fmt.Errorf("unknown proving system type")
return nil, nil, errors.New("unknown proving system type")
}
}
return pssv1, pssv2, nil
Expand Down Expand Up @@ -325,7 +326,7 @@ func WriteProvingSystem(system interface{}, path string, pathVkey string) error
case *ProvingSystemV2:
written, err = s.WriteTo(file)
default:
return fmt.Errorf("unknown proving system type")
return errors.New("unknown proving system type")
}

if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion prover/server/server/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"context"
"encoding/json"
"errors"
"fmt"
"light/light-prover/logging"
"light/light-prover/prover"
Expand Down Expand Up @@ -63,7 +64,7 @@ func (rq *RedisQueue) DequeueProof(queueName string, timeout time.Duration) (*Pr
}

if len(result) < 2 {
return nil, fmt.Errorf("invalid result from Redis")
return nil, errors.New("invalid result from Redis")
}

var job ProofJob
Expand Down
2 changes: 1 addition & 1 deletion prover/server/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (handler proofStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque

jobID := r.URL.Query().Get("job_id")
if jobID == "" {
malformedBodyError(fmt.Errorf("job_id parameter required")).send(w)
malformedBodyError(errors.New("job_id parameter required")).send(w)
return
}

Expand Down