Skip to content
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

adds gnark configurable logger (rs/zerolog) #281

Merged
merged 5 commits into from
Mar 14, 2022
Merged

adds gnark configurable logger (rs/zerolog) #281

merged 5 commits into from
Mar 14, 2022

Conversation

gbotrel
Copy link
Collaborator

@gbotrel gbotrel commented Mar 11, 2022

@gbotrel gbotrel requested a review from ivokub March 11, 2022 16:54
@gbotrel gbotrel added this to the v0.7.0 milestone Mar 11, 2022
@ivokub
Copy link
Collaborator

ivokub commented Mar 14, 2022

Suggested edit:

diff --git a/internal/backend/bls12-377/cs/r1cs.go b/internal/backend/bls12-377/cs/r1cs.go
index 85937a57..1f25eaa7 100644
--- a/internal/backend/bls12-377/cs/r1cs.go
+++ b/internal/backend/bls12-377/cs/r1cs.go
@@ -119,7 +119,7 @@ func (cs *R1CS) Solve(witness, a, b, c []fr.Element, opt backend.ProverConfig) (
 		panic("solver didn't instantiate all wires")
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("constraint system solver done")
+	log.Debug().Dur("took", time.Since(start)).Msg("constraint system solver done")
 
 	return solution.values, nil
 }
diff --git a/internal/backend/bls12-377/cs/r1cs_sparse.go b/internal/backend/bls12-377/cs/r1cs_sparse.go
index a1b68e0f..f9c271aa 100644
--- a/internal/backend/bls12-377/cs/r1cs_sparse.go
+++ b/internal/backend/bls12-377/cs/r1cs_sparse.go
@@ -124,7 +124,7 @@ func (cs *SparseR1CS) Solve(witness []fr.Element, opt backend.ProverConfig) ([]f
 		panic("solver didn't instantiate all wires")
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("constraint system solver done")
+	log.Debug().Dur("took", time.Since(start)).Msg("constraint system solver done")
 
 	return solution.values, nil
 
diff --git a/internal/backend/bls12-377/groth16/prove.go b/internal/backend/bls12-377/groth16/prove.go
index a385e081..707c816c 100644
--- a/internal/backend/bls12-377/groth16/prove.go
+++ b/internal/backend/bls12-377/groth16/prove.go
@@ -267,7 +267,7 @@ func Prove(r1cs *cs.R1CS, pk *ProvingKey, witness bls12_377witness.Witness, opt
 		return nil, err
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("prover done")
+	log.Debug().Dur("took", time.Since(start)).Msg("prover done")
 
 	return proof, nil
 }
diff --git a/internal/backend/bls12-377/groth16/verify.go b/internal/backend/bls12-377/groth16/verify.go
index 5df970cb..679398d1 100644
--- a/internal/backend/bls12-377/groth16/verify.go
+++ b/internal/backend/bls12-377/groth16/verify.go
@@ -84,7 +84,7 @@ func Verify(proof *Proof, vk *VerifyingKey, publicWitness bls12_377witness.Witne
 		return errPairingCheckFailed
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("verifier done")
+	log.Debug().Dur("took", time.Since(start)).Msg("verifier done")
 	return nil
 }
 
diff --git a/internal/backend/bls12-377/plonk/prove.go b/internal/backend/bls12-377/plonk/prove.go
index 73a5957c..6ca6e898 100644
--- a/internal/backend/bls12-377/plonk/prove.go
+++ b/internal/backend/bls12-377/plonk/prove.go
@@ -18,7 +18,6 @@ package plonk
 
 import (
 	"crypto/sha256"
-	"fmt"
 	"math/big"
 	"math/bits"
 	"runtime"
@@ -364,7 +363,7 @@ func Prove(spr *cs.SparseR1CS, pk *ProvingKey, fullWitness bls12_377witness.Witn
 		pk.Vk.KZGSRS,
 	)
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("prover done")
+	log.Debug().Dur("took", time.Since(start)).Msg("prover done")
 
 	if err != nil {
 		return nil, err
diff --git a/internal/backend/bls12-377/plonk/verify.go b/internal/backend/bls12-377/plonk/verify.go
index 72e111b8..36057671 100644
--- a/internal/backend/bls12-377/plonk/verify.go
+++ b/internal/backend/bls12-377/plonk/verify.go
@@ -19,7 +19,6 @@ package plonk
 import (
 	"crypto/sha256"
 	"errors"
-	"fmt"
 	"math/big"
 	"time"
 
@@ -235,7 +234,7 @@ func Verify(proof *Proof, vk *VerifyingKey, publicWitness bls12_377witness.Witne
 		vk.KZGSRS,
 	)
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("verifier done")
+	log.Debug().Dur("took", time.Since(start)).Msg("verifier done")
 
 	return err
 }
diff --git a/internal/backend/bls12-381/cs/r1cs.go b/internal/backend/bls12-381/cs/r1cs.go
index 2263049a..9de9e6d4 100644
--- a/internal/backend/bls12-381/cs/r1cs.go
+++ b/internal/backend/bls12-381/cs/r1cs.go
@@ -119,7 +119,7 @@ func (cs *R1CS) Solve(witness, a, b, c []fr.Element, opt backend.ProverConfig) (
 		panic("solver didn't instantiate all wires")
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("constraint system solver done")
+	log.Debug().Dur("took", time.Since(start)).Msg("constraint system solver done")
 
 	return solution.values, nil
 }
diff --git a/internal/backend/bls12-381/cs/r1cs_sparse.go b/internal/backend/bls12-381/cs/r1cs_sparse.go
index 81db3282..de721d5b 100644
--- a/internal/backend/bls12-381/cs/r1cs_sparse.go
+++ b/internal/backend/bls12-381/cs/r1cs_sparse.go
@@ -124,7 +124,7 @@ func (cs *SparseR1CS) Solve(witness []fr.Element, opt backend.ProverConfig) ([]f
 		panic("solver didn't instantiate all wires")
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("constraint system solver done")
+	log.Debug().Dur("took", time.Since(start)).Msg("constraint system solver done")
 
 	return solution.values, nil
 
diff --git a/internal/backend/bls12-381/groth16/prove.go b/internal/backend/bls12-381/groth16/prove.go
index bd154be1..be61dcf3 100644
--- a/internal/backend/bls12-381/groth16/prove.go
+++ b/internal/backend/bls12-381/groth16/prove.go
@@ -267,7 +267,7 @@ func Prove(r1cs *cs.R1CS, pk *ProvingKey, witness bls12_381witness.Witness, opt
 		return nil, err
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("prover done")
+	log.Debug().Dur("took", time.Since(start)).Msg("prover done")
 
 	return proof, nil
 }
diff --git a/internal/backend/bls12-381/groth16/verify.go b/internal/backend/bls12-381/groth16/verify.go
index adf07b07..c410c395 100644
--- a/internal/backend/bls12-381/groth16/verify.go
+++ b/internal/backend/bls12-381/groth16/verify.go
@@ -84,7 +84,7 @@ func Verify(proof *Proof, vk *VerifyingKey, publicWitness bls12_381witness.Witne
 		return errPairingCheckFailed
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("verifier done")
+	log.Debug().Dur("took", time.Since(start)).Msg("verifier done")
 	return nil
 }
 
diff --git a/internal/backend/bls12-381/plonk/prove.go b/internal/backend/bls12-381/plonk/prove.go
index 09a6533b..0d7020cf 100644
--- a/internal/backend/bls12-381/plonk/prove.go
+++ b/internal/backend/bls12-381/plonk/prove.go
@@ -18,7 +18,6 @@ package plonk
 
 import (
 	"crypto/sha256"
-	"fmt"
 	"math/big"
 	"math/bits"
 	"runtime"
@@ -364,7 +363,7 @@ func Prove(spr *cs.SparseR1CS, pk *ProvingKey, fullWitness bls12_381witness.Witn
 		pk.Vk.KZGSRS,
 	)
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("prover done")
+	log.Debug().Dur("took", time.Since(start)).Msg("prover done")
 
 	if err != nil {
 		return nil, err
diff --git a/internal/backend/bls12-381/plonk/verify.go b/internal/backend/bls12-381/plonk/verify.go
index 26fd6142..545b6088 100644
--- a/internal/backend/bls12-381/plonk/verify.go
+++ b/internal/backend/bls12-381/plonk/verify.go
@@ -19,7 +19,6 @@ package plonk
 import (
 	"crypto/sha256"
 	"errors"
-	"fmt"
 	"math/big"
 	"time"
 
@@ -235,7 +234,7 @@ func Verify(proof *Proof, vk *VerifyingKey, publicWitness bls12_381witness.Witne
 		vk.KZGSRS,
 	)
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("verifier done")
+	log.Debug().Dur("took", time.Since(start)).Msg("verifier done")
 
 	return err
 }
diff --git a/internal/backend/bls24-315/cs/r1cs.go b/internal/backend/bls24-315/cs/r1cs.go
index 28fe6378..9266a498 100644
--- a/internal/backend/bls24-315/cs/r1cs.go
+++ b/internal/backend/bls24-315/cs/r1cs.go
@@ -119,7 +119,7 @@ func (cs *R1CS) Solve(witness, a, b, c []fr.Element, opt backend.ProverConfig) (
 		panic("solver didn't instantiate all wires")
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("constraint system solver done")
+	log.Debug().Dur("took", time.Since(start)).Msg("constraint system solver done")
 
 	return solution.values, nil
 }
diff --git a/internal/backend/bls24-315/cs/r1cs_sparse.go b/internal/backend/bls24-315/cs/r1cs_sparse.go
index 02276c90..a81cc9e0 100644
--- a/internal/backend/bls24-315/cs/r1cs_sparse.go
+++ b/internal/backend/bls24-315/cs/r1cs_sparse.go
@@ -124,7 +124,7 @@ func (cs *SparseR1CS) Solve(witness []fr.Element, opt backend.ProverConfig) ([]f
 		panic("solver didn't instantiate all wires")
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("constraint system solver done")
+	log.Debug().Dur("took", time.Since(start)).Msg("constraint system solver done")
 
 	return solution.values, nil
 
diff --git a/internal/backend/bls24-315/groth16/prove.go b/internal/backend/bls24-315/groth16/prove.go
index 124f400f..ccee7f26 100644
--- a/internal/backend/bls24-315/groth16/prove.go
+++ b/internal/backend/bls24-315/groth16/prove.go
@@ -267,7 +267,7 @@ func Prove(r1cs *cs.R1CS, pk *ProvingKey, witness bls24_315witness.Witness, opt
 		return nil, err
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("prover done")
+	log.Debug().Dur("took", time.Since(start)).Msg("prover done")
 
 	return proof, nil
 }
diff --git a/internal/backend/bls24-315/groth16/verify.go b/internal/backend/bls24-315/groth16/verify.go
index 0cbc6b1e..e15c9653 100644
--- a/internal/backend/bls24-315/groth16/verify.go
+++ b/internal/backend/bls24-315/groth16/verify.go
@@ -84,7 +84,7 @@ func Verify(proof *Proof, vk *VerifyingKey, publicWitness bls24_315witness.Witne
 		return errPairingCheckFailed
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("verifier done")
+	log.Debug().Dur("took", time.Since(start)).Msg("verifier done")
 	return nil
 }
 
diff --git a/internal/backend/bls24-315/plonk/prove.go b/internal/backend/bls24-315/plonk/prove.go
index 7c6864f7..b12d9a9c 100644
--- a/internal/backend/bls24-315/plonk/prove.go
+++ b/internal/backend/bls24-315/plonk/prove.go
@@ -18,7 +18,6 @@ package plonk
 
 import (
 	"crypto/sha256"
-	"fmt"
 	"math/big"
 	"math/bits"
 	"runtime"
@@ -364,7 +363,7 @@ func Prove(spr *cs.SparseR1CS, pk *ProvingKey, fullWitness bls24_315witness.Witn
 		pk.Vk.KZGSRS,
 	)
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("prover done")
+	log.Debug().Dur("took", time.Since(start)).Msg("prover done")
 
 	if err != nil {
 		return nil, err
diff --git a/internal/backend/bls24-315/plonk/verify.go b/internal/backend/bls24-315/plonk/verify.go
index 799e170a..6182f143 100644
--- a/internal/backend/bls24-315/plonk/verify.go
+++ b/internal/backend/bls24-315/plonk/verify.go
@@ -19,7 +19,6 @@ package plonk
 import (
 	"crypto/sha256"
 	"errors"
-	"fmt"
 	"math/big"
 	"time"
 
@@ -235,7 +234,7 @@ func Verify(proof *Proof, vk *VerifyingKey, publicWitness bls24_315witness.Witne
 		vk.KZGSRS,
 	)
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("verifier done")
+	log.Debug().Dur("took", time.Since(start)).Msg("verifier done")
 
 	return err
 }
diff --git a/internal/backend/bn254/cs/r1cs.go b/internal/backend/bn254/cs/r1cs.go
index a56ae540..524aa229 100644
--- a/internal/backend/bn254/cs/r1cs.go
+++ b/internal/backend/bn254/cs/r1cs.go
@@ -119,7 +119,7 @@ func (cs *R1CS) Solve(witness, a, b, c []fr.Element, opt backend.ProverConfig) (
 		panic("solver didn't instantiate all wires")
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("constraint system solver done")
+	log.Debug().Dur("took", time.Since(start)).Msg("constraint system solver done")
 
 	return solution.values, nil
 }
diff --git a/internal/backend/bn254/cs/r1cs_sparse.go b/internal/backend/bn254/cs/r1cs_sparse.go
index 2a2d5926..59ce8307 100644
--- a/internal/backend/bn254/cs/r1cs_sparse.go
+++ b/internal/backend/bn254/cs/r1cs_sparse.go
@@ -124,7 +124,7 @@ func (cs *SparseR1CS) Solve(witness []fr.Element, opt backend.ProverConfig) ([]f
 		panic("solver didn't instantiate all wires")
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("constraint system solver done")
+	log.Debug().Dur("took", time.Since(start)).Msg("constraint system solver done")
 
 	return solution.values, nil
 
diff --git a/internal/backend/bn254/groth16/prove.go b/internal/backend/bn254/groth16/prove.go
index 26bfa7f3..6394ca0c 100644
--- a/internal/backend/bn254/groth16/prove.go
+++ b/internal/backend/bn254/groth16/prove.go
@@ -267,7 +267,7 @@ func Prove(r1cs *cs.R1CS, pk *ProvingKey, witness bn254witness.Witness, opt back
 		return nil, err
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("prover done")
+	log.Debug().Dur("took", time.Since(start)).Msg("prover done")
 
 	return proof, nil
 }
diff --git a/internal/backend/bn254/groth16/verify.go b/internal/backend/bn254/groth16/verify.go
index f9ce01d8..0af30801 100644
--- a/internal/backend/bn254/groth16/verify.go
+++ b/internal/backend/bn254/groth16/verify.go
@@ -86,7 +86,7 @@ func Verify(proof *Proof, vk *VerifyingKey, publicWitness bn254witness.Witness)
 		return errPairingCheckFailed
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("verifier done")
+	log.Debug().Dur("took", time.Since(start)).Msg("verifier done")
 	return nil
 }
 
diff --git a/internal/backend/bn254/plonk/prove.go b/internal/backend/bn254/plonk/prove.go
index ca666050..71c1f8b0 100644
--- a/internal/backend/bn254/plonk/prove.go
+++ b/internal/backend/bn254/plonk/prove.go
@@ -18,7 +18,6 @@ package plonk
 
 import (
 	"crypto/sha256"
-	"fmt"
 	"math/big"
 	"math/bits"
 	"runtime"
@@ -364,7 +363,7 @@ func Prove(spr *cs.SparseR1CS, pk *ProvingKey, fullWitness bn254witness.Witness,
 		pk.Vk.KZGSRS,
 	)
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("prover done")
+	log.Debug().Dur("took", time.Since(start)).Msg("prover done")
 
 	if err != nil {
 		return nil, err
diff --git a/internal/backend/bn254/plonk/verify.go b/internal/backend/bn254/plonk/verify.go
index 684b53db..c612dd4b 100644
--- a/internal/backend/bn254/plonk/verify.go
+++ b/internal/backend/bn254/plonk/verify.go
@@ -19,7 +19,6 @@ package plonk
 import (
 	"crypto/sha256"
 	"errors"
-	"fmt"
 	"math/big"
 	"time"
 
@@ -235,7 +234,7 @@ func Verify(proof *Proof, vk *VerifyingKey, publicWitness bn254witness.Witness)
 		vk.KZGSRS,
 	)
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("verifier done")
+	log.Debug().Dur("took", time.Since(start)).Msg("verifier done")
 
 	return err
 }
diff --git a/internal/backend/bw6-633/cs/r1cs.go b/internal/backend/bw6-633/cs/r1cs.go
index 8aefc109..9ac395c4 100644
--- a/internal/backend/bw6-633/cs/r1cs.go
+++ b/internal/backend/bw6-633/cs/r1cs.go
@@ -119,7 +119,7 @@ func (cs *R1CS) Solve(witness, a, b, c []fr.Element, opt backend.ProverConfig) (
 		panic("solver didn't instantiate all wires")
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("constraint system solver done")
+	log.Debug().Dur("took", time.Since(start)).Msg("constraint system solver done")
 
 	return solution.values, nil
 }
diff --git a/internal/backend/bw6-633/cs/r1cs_sparse.go b/internal/backend/bw6-633/cs/r1cs_sparse.go
index c3fa8da1..65e168c2 100644
--- a/internal/backend/bw6-633/cs/r1cs_sparse.go
+++ b/internal/backend/bw6-633/cs/r1cs_sparse.go
@@ -124,7 +124,7 @@ func (cs *SparseR1CS) Solve(witness []fr.Element, opt backend.ProverConfig) ([]f
 		panic("solver didn't instantiate all wires")
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("constraint system solver done")
+	log.Debug().Dur("took", time.Since(start)).Msg("constraint system solver done")
 
 	return solution.values, nil
 
diff --git a/internal/backend/bw6-633/groth16/prove.go b/internal/backend/bw6-633/groth16/prove.go
index 0ca049d8..17b607cd 100644
--- a/internal/backend/bw6-633/groth16/prove.go
+++ b/internal/backend/bw6-633/groth16/prove.go
@@ -267,7 +267,7 @@ func Prove(r1cs *cs.R1CS, pk *ProvingKey, witness bw6_633witness.Witness, opt ba
 		return nil, err
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("prover done")
+	log.Debug().Dur("took", time.Since(start)).Msg("prover done")
 
 	return proof, nil
 }
diff --git a/internal/backend/bw6-633/groth16/verify.go b/internal/backend/bw6-633/groth16/verify.go
index 581394fb..b29532d2 100644
--- a/internal/backend/bw6-633/groth16/verify.go
+++ b/internal/backend/bw6-633/groth16/verify.go
@@ -84,7 +84,7 @@ func Verify(proof *Proof, vk *VerifyingKey, publicWitness bw6_633witness.Witness
 		return errPairingCheckFailed
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("verifier done")
+	log.Debug().Dur("took", time.Since(start)).Msg("verifier done")
 	return nil
 }
 
diff --git a/internal/backend/bw6-633/plonk/prove.go b/internal/backend/bw6-633/plonk/prove.go
index 5b4f0195..168065ae 100644
--- a/internal/backend/bw6-633/plonk/prove.go
+++ b/internal/backend/bw6-633/plonk/prove.go
@@ -18,7 +18,6 @@ package plonk
 
 import (
 	"crypto/sha256"
-	"fmt"
 	"math/big"
 	"math/bits"
 	"runtime"
@@ -364,7 +363,7 @@ func Prove(spr *cs.SparseR1CS, pk *ProvingKey, fullWitness bw6_633witness.Witnes
 		pk.Vk.KZGSRS,
 	)
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("prover done")
+	log.Debug().Dur("took", time.Since(start)).Msg("prover done")
 
 	if err != nil {
 		return nil, err
diff --git a/internal/backend/bw6-633/plonk/verify.go b/internal/backend/bw6-633/plonk/verify.go
index f48fcdef..e8d2f115 100644
--- a/internal/backend/bw6-633/plonk/verify.go
+++ b/internal/backend/bw6-633/plonk/verify.go
@@ -19,7 +19,6 @@ package plonk
 import (
 	"crypto/sha256"
 	"errors"
-	"fmt"
 	"math/big"
 	"time"
 
@@ -235,7 +234,7 @@ func Verify(proof *Proof, vk *VerifyingKey, publicWitness bw6_633witness.Witness
 		vk.KZGSRS,
 	)
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("verifier done")
+	log.Debug().Dur("took", time.Since(start)).Msg("verifier done")
 
 	return err
 }
diff --git a/internal/backend/bw6-761/cs/r1cs.go b/internal/backend/bw6-761/cs/r1cs.go
index 79f3a1fb..548f0cc5 100644
--- a/internal/backend/bw6-761/cs/r1cs.go
+++ b/internal/backend/bw6-761/cs/r1cs.go
@@ -119,7 +119,7 @@ func (cs *R1CS) Solve(witness, a, b, c []fr.Element, opt backend.ProverConfig) (
 		panic("solver didn't instantiate all wires")
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("constraint system solver done")
+	log.Debug().Dur("took", time.Since(start)).Msg("constraint system solver done")
 
 	return solution.values, nil
 }
diff --git a/internal/backend/bw6-761/cs/r1cs_sparse.go b/internal/backend/bw6-761/cs/r1cs_sparse.go
index 4dc47418..14a05b93 100644
--- a/internal/backend/bw6-761/cs/r1cs_sparse.go
+++ b/internal/backend/bw6-761/cs/r1cs_sparse.go
@@ -124,7 +124,7 @@ func (cs *SparseR1CS) Solve(witness []fr.Element, opt backend.ProverConfig) ([]f
 		panic("solver didn't instantiate all wires")
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("constraint system solver done")
+	log.Debug().Dur("took", time.Since(start)).Msg("constraint system solver done")
 
 	return solution.values, nil
 
diff --git a/internal/backend/bw6-761/groth16/prove.go b/internal/backend/bw6-761/groth16/prove.go
index 306f31e5..ced40afe 100644
--- a/internal/backend/bw6-761/groth16/prove.go
+++ b/internal/backend/bw6-761/groth16/prove.go
@@ -267,7 +267,7 @@ func Prove(r1cs *cs.R1CS, pk *ProvingKey, witness bw6_761witness.Witness, opt ba
 		return nil, err
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("prover done")
+	log.Debug().Dur("took", time.Since(start)).Msg("prover done")
 
 	return proof, nil
 }
diff --git a/internal/backend/bw6-761/groth16/verify.go b/internal/backend/bw6-761/groth16/verify.go
index 36b6cbc7..aaf2e7ee 100644
--- a/internal/backend/bw6-761/groth16/verify.go
+++ b/internal/backend/bw6-761/groth16/verify.go
@@ -84,7 +84,7 @@ func Verify(proof *Proof, vk *VerifyingKey, publicWitness bw6_761witness.Witness
 		return errPairingCheckFailed
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("verifier done")
+	log.Debug().Dur("took", time.Since(start)).Msg("verifier done")
 	return nil
 }
 
diff --git a/internal/backend/bw6-761/plonk/prove.go b/internal/backend/bw6-761/plonk/prove.go
index 5be64d19..af31f365 100644
--- a/internal/backend/bw6-761/plonk/prove.go
+++ b/internal/backend/bw6-761/plonk/prove.go
@@ -18,7 +18,6 @@ package plonk
 
 import (
 	"crypto/sha256"
-	"fmt"
 	"math/big"
 	"math/bits"
 	"runtime"
@@ -364,7 +363,7 @@ func Prove(spr *cs.SparseR1CS, pk *ProvingKey, fullWitness bw6_761witness.Witnes
 		pk.Vk.KZGSRS,
 	)
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("prover done")
+	log.Debug().Dur("took", time.Since(start)).Msg("prover done")
 
 	if err != nil {
 		return nil, err
diff --git a/internal/backend/bw6-761/plonk/verify.go b/internal/backend/bw6-761/plonk/verify.go
index 7854eeb5..67888580 100644
--- a/internal/backend/bw6-761/plonk/verify.go
+++ b/internal/backend/bw6-761/plonk/verify.go
@@ -19,7 +19,6 @@ package plonk
 import (
 	"crypto/sha256"
 	"errors"
-	"fmt"
 	"math/big"
 	"time"
 
@@ -235,7 +234,7 @@ func Verify(proof *Proof, vk *VerifyingKey, publicWitness bw6_761witness.Witness
 		vk.KZGSRS,
 	)
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("verifier done")
+	log.Debug().Dur("took", time.Since(start)).Msg("verifier done")
 
 	return err
 }
diff --git a/internal/generator/backend/template/representations/r1cs.go.tmpl b/internal/generator/backend/template/representations/r1cs.go.tmpl
index 3db7bbf1..c0c11bea 100644
--- a/internal/generator/backend/template/representations/r1cs.go.tmpl
+++ b/internal/generator/backend/template/representations/r1cs.go.tmpl
@@ -104,7 +104,7 @@ func (cs *R1CS) Solve(witness, a, b, c []fr.Element, opt backend.ProverConfig) (
 	}
 
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("constraint system solver done")
+	log.Debug().Dur("took", time.Since(start)).Msg("constraint system solver done")
 
 	return solution.values, nil
 }
diff --git a/internal/generator/backend/template/representations/r1cs.sparse.go.tmpl b/internal/generator/backend/template/representations/r1cs.sparse.go.tmpl
index ab0e59bb..0f323d19 100644
--- a/internal/generator/backend/template/representations/r1cs.sparse.go.tmpl
+++ b/internal/generator/backend/template/representations/r1cs.sparse.go.tmpl
@@ -107,7 +107,7 @@ func (cs *SparseR1CS) Solve(witness []fr.Element, opt backend.ProverConfig) ([]f
 		panic("solver didn't instantiate all wires")
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("constraint system solver done")
+	log.Debug().Dur("took", time.Since(start)).Msg("constraint system solver done")
 
 	return solution.values, nil
 
diff --git a/internal/generator/backend/template/zkpschemes/groth16/groth16.prove.go.tmpl b/internal/generator/backend/template/zkpschemes/groth16/groth16.prove.go.tmpl
index 7a5b6d4e..a37b7ebd 100644
--- a/internal/generator/backend/template/zkpschemes/groth16/groth16.prove.go.tmpl
+++ b/internal/generator/backend/template/zkpschemes/groth16/groth16.prove.go.tmpl
@@ -246,7 +246,7 @@ func Prove(r1cs *cs.R1CS, pk *ProvingKey, witness {{ toLower .CurveID }}witness.
 		return nil, err 
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("prover done")
+	log.Debug().Dur("took", time.Since(start)).Msg("prover done")
 
 	return proof, nil
 }
diff --git a/internal/generator/backend/template/zkpschemes/groth16/groth16.verify.go.tmpl b/internal/generator/backend/template/zkpschemes/groth16/groth16.verify.go.tmpl
index 48f203a9..67ca650e 100644
--- a/internal/generator/backend/template/zkpschemes/groth16/groth16.verify.go.tmpl
+++ b/internal/generator/backend/template/zkpschemes/groth16/groth16.verify.go.tmpl
@@ -66,7 +66,7 @@ func Verify(proof *Proof, vk *VerifyingKey, publicWitness {{ toLower .CurveID}}w
 		return errPairingCheckFailed
 	}
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("verifier done")
+	log.Debug().Dur("took", time.Since(start)).Msg("verifier done")
 	return nil
 }
 
diff --git a/internal/generator/backend/template/zkpschemes/plonk/plonk.prove.go.tmpl b/internal/generator/backend/template/zkpschemes/plonk/plonk.prove.go.tmpl
index 536ce550..f0a94876 100644
--- a/internal/generator/backend/template/zkpschemes/plonk/plonk.prove.go.tmpl
+++ b/internal/generator/backend/template/zkpschemes/plonk/plonk.prove.go.tmpl
@@ -5,7 +5,6 @@ import (
 	"sync"
 	"runtime"
 	"time"
-	"fmt"
 
 	{{ template "import_fr" . }}
 	{{ template "import_curve" . }}
@@ -342,7 +341,7 @@ func Prove(spr *cs.SparseR1CS, pk *ProvingKey, fullWitness {{ toLower .CurveID }
 		pk.Vk.KZGSRS,
 	)
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("prover done")
+	log.Debug().Dur("took", time.Since(start)).Msg("prover done")
 
 	if err != nil {
 		return nil, err
diff --git a/internal/generator/backend/template/zkpschemes/plonk/plonk.verify.go.tmpl b/internal/generator/backend/template/zkpschemes/plonk/plonk.verify.go.tmpl
index 15fd7272..38e090ad 100644
--- a/internal/generator/backend/template/zkpschemes/plonk/plonk.verify.go.tmpl
+++ b/internal/generator/backend/template/zkpschemes/plonk/plonk.verify.go.tmpl
@@ -3,7 +3,6 @@ import (
 	"errors"
 	"math/big"
 	"time"
-	"fmt"
 
 	{{ template "import_fr" . }}
 	{{ template "import_kzg" . }}
@@ -214,7 +213,7 @@ func Verify(proof *Proof, vk *VerifyingKey, publicWitness {{ toLower .CurveID }}
 		vk.KZGSRS,
 	)
 
-	log.Debug().Str("took", fmt.Sprintf("%dms", time.Since(start).Milliseconds())).Msg("verifier done")
+	log.Debug().Dur("took", time.Since(start)).Msg("verifier done")
 
 	return err 
 }
diff --git a/logger/logger.go b/logger/logger.go
index 6ac7b534..3a5e186c 100644
--- a/logger/logger.go
+++ b/logger/logger.go
@@ -1,4 +1,5 @@
 // Package logger provides a configurable logger accross gnark components
+//
 // The root logger defined by default uses github.com/rs/zerolog with a console writer
 package logger
 

Copy link
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zerolog looks seems to be very fast and nicely designed logger. PR looks good. I only changed a few calls to the logger to use Dur() instead of formatting time duration with fmt.Sprintf. Now it is possible to change the precision of logging from a single place (zerolog.DurationFieldUnit). But the current version is also OK (and bit more explicit, as zerolog does not display time unit). See if changing makes sense.

@gbotrel gbotrel merged commit c679d5f into develop Mar 14, 2022
@gbotrel gbotrel deleted the feat/logger branch March 14, 2022 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants