feat: implement slog-based logging#1769
Conversation
There was a problem hiding this comment.
Pull request overview
This PR starts migrating gnark’s logging from the legacy github.com/consensys/gnark/logger (zerolog-based) to Go’s standard log/slog, introducing an internal slog logger with environment-based configuration and wiring logger instances through compile/solve/prove/verify entry points while keeping backward compatibility.
Changes:
- Add
internal/logger(slog-based) withGNARK_LOG_LEVELconfiguration and a zerolog compatibility adapter. - Thread
*slog.Loggerthrough frontend compilation, constraint solving, and backend prover/verifier configs (including templates and accelerated/icicle paths). - Deprecate the public
loggerpackage and update docs/tests to reflect the new logging output and configuration.
Reviewed changes
Copilot reviewed 49 out of 76 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/unsafekzg/options.go | Switch unsafe-KZG cache logging to internal slog logger. |
| test/unsafekzg/kzgsrs.go | Convert KZG SRS cache logging to slog + trace helper. |
| test/solver_test.go | Disable solver logging via slog-based solver option in tests; skip tinyfield-incompatible circuits. |
| test/engine.go | Add slog logger plumbing to test engine and trace/debug timings/counters. |
| test/assert_solidity.go | Use slog logger for solidity checker execution logs. |
| test/assert_options.go | Add assertion logger option using slog/internal logger. |
| test/assert_checkcircuit.go | Use structured slog logging throughout circuit checks. |
| std/rangecheck/rangecheck_commit.go | Route rangechecker warning via compiler logger (slog). |
| std/math/emulated/field.go | Replace zerolog usage with slog logger and trace-level compile logging. |
| std/algebra/native/sw_grumpkin/g1.go | Migrate compile-time deprecation log to slog level. |
| std/algebra/native/sw_bls12377/g1.go | Migrate compile-time deprecation log to slog level. |
| std/algebra/emulated/sw_bls12381/g2.go | Migrate compile-time deprecation log to slog level. |
| README.md | Document GNARK_LOG_LEVEL and default behavior. |
| profile/profile.go | Replace zerolog-style calls with slog; adjust fatal paths to exit after error log. |
| logger/logger.go | Deprecate legacy logger package; back it with internal slog logger + one-time warning. |
| internal/widecommitter/widecommitter.go | Emit warning via compiler logger (slog). |
| internal/logger/zerolog.go | Add bidirectional slog↔zerolog adapters for compatibility. |
| internal/logger/logger.go | Add internal default slog logger with env-configured levels and runtime metadata. |
| internal/logger/logger_test.go | Add tests for env level parsing, output behavior, source inclusion, and quiet mode. |
| internal/generator/backend/template/zkpschemes/plonk/plonk.verify.go.tmpl | Template: use verifier config logger (slog) and structured duration logging. |
| internal/generator/backend/template/zkpschemes/plonk/plonk.prove.go.tmpl | Template: use prover config logger (slog) and pass logger into solver options. |
| internal/generator/backend/template/zkpschemes/groth16/groth16.verify.go.tmpl | Template: use verifier config logger (slog) and structured duration logging. |
| internal/generator/backend/template/zkpschemes/groth16/groth16.prove.go.tmpl | Template: use prover config logger (slog) and pass logger into solver options. |
| internal/generator/backend/template/representations/system.go.tmpl | Template: parse solver config once, use slog logger, pass config into solver ctor. |
| internal/generator/backend/template/representations/solver.go.tmpl | Template: switch solver logging to slog for api.Println replay. |
| internal/compilelogger/compilelogger.go | Switch compile-time logging to compiler slog logger. |
| internal/compilelogger/compilelogger_test.go | Update tests/examples to use slog loggers via frontend.WithLogger. |
| frontend/schema/walk.go | Convert schema warnings to structured slog calls. |
| frontend/schema/schema.go | Convert schema warnings to structured slog calls. |
| frontend/cs/scs/builder.go | Expose compiler logger and emit build warnings via slog. |
| frontend/cs/r1cs/builder.go | Expose compiler logger and emit build warnings via slog. |
| frontend/cs/commitment.go | Update commitment placeholder warning to slog/internal logger. |
| frontend/compile.go | Add compilation logger option and structured compile timing/metadata logs. |
| frontend/builder.go | Extend frontend.Compiler interface to expose Logger() *slog.Logger. |
| debug_test.go | Update expected println trace output to slog text handler format. |
| constraint/tinyfield/system.go | Use slog logger from solver config; pass config into solver ctor. |
| constraint/tinyfield/solver.go | Switch solver printLogs plumbing to slog. |
| constraint/solver/options.go | Migrate solver config logger to *slog.Logger and add adapter-based WithLogger. |
| constraint/solver/hint_registry.go | Use internal slog trace logging for duplicate hint registrations. |
| constraint/koalabear/system.go | Use slog logger from solver config; pass config into solver ctor. |
| constraint/koalabear/solver.go | Switch solver printLogs plumbing to slog. |
| constraint/grumpkin/system.go | Use slog logger from solver config; pass config into solver ctor. |
| constraint/grumpkin/solver.go | Switch solver printLogs plumbing to slog. |
| constraint/core.go | Convert serialization header warning to structured slog. |
| constraint/bw6-761/system.go | Use slog logger from solver config; pass config into solver ctor. |
| constraint/bw6-761/solver.go | Switch solver printLogs plumbing to slog. |
| constraint/bn254/system.go | Use slog logger from solver config; pass config into solver ctor. |
| constraint/bn254/solver.go | Switch solver printLogs plumbing to slog. |
| constraint/bls12-381/system.go | Use slog logger from solver config; pass config into solver ctor. |
| constraint/bls12-381/solver.go | Switch solver printLogs plumbing to slog. |
| constraint/bls12-377/system.go | Use slog logger from solver config; pass config into solver ctor. |
| constraint/bls12-377/solver.go | Switch solver printLogs plumbing to slog. |
| constraint/babybear/system.go | Use slog logger from solver config; pass config into solver ctor. |
| constraint/babybear/solver.go | Switch solver printLogs plumbing to slog. |
| backend/plonk/bw6-761/verify.go | Use verifier config logger (slog) and structured duration logging. |
| backend/plonk/bw6-761/prove.go | Use prover config logger (slog) and pass logger into solver options. |
| backend/plonk/bn254/verify.go | Use verifier config logger (slog) and structured duration logging. |
| backend/plonk/bn254/prove.go | Use prover config logger (slog) and pass logger into solver options. |
| backend/plonk/bls12-381/verify.go | Use verifier config logger (slog) and structured duration logging. |
| backend/plonk/bls12-381/prove.go | Use prover config logger (slog) and pass logger into solver options. |
| backend/plonk/bls12-377/verify.go | Use verifier config logger (slog) and structured duration logging. |
| backend/plonk/bls12-377/prove.go | Use prover config logger (slog) and pass logger into solver options. |
| backend/groth16/bw6-761/verify.go | Use verifier config logger (slog) and structured duration logging. |
| backend/groth16/bw6-761/prove.go | Use prover config logger (slog) and pass logger into solver options. |
| backend/groth16/bn254/verify.go | Use verifier config logger (slog) and structured duration logging. |
| backend/groth16/bn254/prove.go | Use prover config logger (slog) and pass logger into solver options. |
| backend/groth16/bls12-381/verify.go | Use verifier config logger (slog) and structured duration logging. |
| backend/groth16/bls12-381/prove.go | Use prover config logger (slog) and pass logger into solver options. |
| backend/groth16/bls12-377/verify.go | Use verifier config logger (slog) and structured duration logging. |
| backend/groth16/bls12-377/prove.go | Use prover config logger (slog) and pass logger into solver options. |
| backend/backend.go | Add prover/verifier logger fields and options to inject slog logger. |
| backend/accelerated/icicle/internal/generator/templates/groth16.icicle.go.tmpl | Template: use slog logger and pass logger into solver options + trace GPU lifecycle logs. |
| backend/accelerated/icicle/groth16/bw6-761/icicle.go | Use internal slog logger and pass logger into solver options + trace GPU lifecycle logs. |
| backend/accelerated/icicle/groth16/bn254/icicle.go | Use internal slog logger and pass logger into solver options + trace GPU lifecycle logs. |
| backend/accelerated/icicle/groth16/bls12-381/icicle.go | Use internal slog logger and pass logger into solver options + trace GPU lifecycle logs. |
| backend/accelerated/icicle/groth16/bls12-377/icicle.go | Use internal slog logger and pass logger into solver options + trace GPU lifecycle logs. |
Files not reviewed (27)
- backend/accelerated/icicle/groth16/bls12-377/icicle.go: Language not supported
- backend/accelerated/icicle/groth16/bls12-381/icicle.go: Language not supported
- backend/accelerated/icicle/groth16/bn254/icicle.go: Language not supported
- backend/accelerated/icicle/groth16/bw6-761/icicle.go: Language not supported
- backend/groth16/bls12-377/prove.go: Language not supported
- backend/groth16/bls12-377/verify.go: Language not supported
- backend/groth16/bls12-381/prove.go: Language not supported
- backend/groth16/bls12-381/verify.go: Language not supported
- backend/groth16/bn254/prove.go: Language not supported
- backend/groth16/bn254/verify.go: Language not supported
- backend/groth16/bw6-761/prove.go: Language not supported
- backend/groth16/bw6-761/verify.go: Language not supported
- backend/plonk/bls12-377/prove.go: Language not supported
- backend/plonk/bls12-377/verify.go: Language not supported
- backend/plonk/bls12-381/prove.go: Language not supported
- backend/plonk/bls12-381/verify.go: Language not supported
- backend/plonk/bn254/prove.go: Language not supported
- backend/plonk/bn254/verify.go: Language not supported
- backend/plonk/bw6-761/prove.go: Language not supported
- backend/plonk/bw6-761/verify.go: Language not supported
- constraint/babybear/solver.go: Language not supported
- constraint/babybear/system.go: Language not supported
- constraint/bls12-377/solver.go: Language not supported
- constraint/bls12-377/system.go: Language not supported
- constraint/bls12-381/solver.go: Language not supported
- constraint/bls12-381/system.go: Language not supported
- constraint/bn254/solver.go: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 83 out of 107 changed files in this pull request and generated 1 comment.
Files not reviewed (24)
- backend/accelerated/icicle/groth16/bls12-377/icicle.go: Language not supported
- backend/accelerated/icicle/groth16/bls12-381/icicle.go: Language not supported
- backend/accelerated/icicle/groth16/bn254/icicle.go: Language not supported
- backend/accelerated/icicle/groth16/bw6-761/icicle.go: Language not supported
- backend/groth16/bls12-377/marshal.go: Language not supported
- backend/groth16/bls12-377/mpcsetup/marshal.go: Language not supported
- backend/groth16/bls12-377/prove.go: Language not supported
- backend/groth16/bls12-377/verify.go: Language not supported
- backend/groth16/bls12-381/marshal.go: Language not supported
- backend/groth16/bls12-381/mpcsetup/marshal.go: Language not supported
- backend/groth16/bls12-381/prove.go: Language not supported
- backend/groth16/bls12-381/verify.go: Language not supported
- backend/groth16/bn254/marshal.go: Language not supported
- backend/groth16/bn254/mpcsetup/marshal.go: Language not supported
- backend/groth16/bn254/prove.go: Language not supported
- backend/groth16/bn254/verify.go: Language not supported
- backend/groth16/bw6-761/marshal.go: Language not supported
- backend/groth16/bw6-761/mpcsetup/marshal.go: Language not supported
- backend/groth16/bw6-761/prove.go: Language not supported
- backend/groth16/bw6-761/verify.go: Language not supported
- backend/plonk/bls12-377/marshal.go: Language not supported
- backend/plonk/bls12-377/prove.go: Language not supported
- backend/plonk/bls12-377/verify.go: Language not supported
- backend/plonk/bls12-381/marshal.go: Language not supported
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 84 out of 107 changed files in this pull request and generated 2 comments.
Files not reviewed (23)
- backend/accelerated/icicle/groth16/bls12-377/icicle.go: Language not supported
- backend/accelerated/icicle/groth16/bls12-381/icicle.go: Language not supported
- backend/accelerated/icicle/groth16/bn254/icicle.go: Language not supported
- backend/accelerated/icicle/groth16/bw6-761/icicle.go: Language not supported
- backend/groth16/bls12-377/marshal.go: Language not supported
- backend/groth16/bls12-377/mpcsetup/marshal.go: Language not supported
- backend/groth16/bls12-377/prove.go: Language not supported
- backend/groth16/bls12-377/verify.go: Language not supported
- backend/groth16/bls12-381/marshal.go: Language not supported
- backend/groth16/bls12-381/mpcsetup/marshal.go: Language not supported
- backend/groth16/bls12-381/prove.go: Language not supported
- backend/groth16/bls12-381/verify.go: Language not supported
- backend/groth16/bn254/marshal.go: Language not supported
- backend/groth16/bn254/mpcsetup/marshal.go: Language not supported
- backend/groth16/bn254/prove.go: Language not supported
- backend/groth16/bn254/verify.go: Language not supported
- backend/groth16/bw6-761/marshal.go: Language not supported
- backend/groth16/bw6-761/mpcsetup/marshal.go: Language not supported
- backend/groth16/bw6-761/prove.go: Language not supported
- backend/groth16/bw6-761/verify.go: Language not supported
- backend/plonk/bls12-377/marshal.go: Language not supported
- backend/plonk/bls12-377/prove.go: Language not supported
- backend/plonk/bls12-377/verify.go: Language not supported
|
@gbotrel - ready for review now. It should be backwards compatible, but we dispatch a message indicating that the users should avoid using the old zerolog based implementation. And now the new logger is internal, used only internally inside gnark. If the user wants to provide their custom logger, then they can provide their own initialized slog into frontend/backend etc. We also now print out some runtime status so that its easier to debug the capabilities of the system. I was thinking about also querying AWS instance info (i.e. the machine type etc), but postponed for now. I would say biggest difference is that now I also added Trace level for tracing different steps and made DEBUG level less noisy. Now the log level can also be set using GNARK_LOG_LEVEL tag (by default we are INFO, unless build tag |
Description
Start migration to
log/slogwhich is a structured logger in standard library. Currently still backwards compatible, but will remove theloggerpackage in the future to only provide entry points during compile, solve, prove and verify to plug in custom handlers.Type of change
How has this been tested?
How has this been benchmarked?
Checklist:
golangci-lintdoes not output errors locallyNote
Medium Risk
Wide mechanical logging refactor across prove/verify and GPU paths; behavior changes mainly in log volume/levels and logger injection, not proof logic, but touches critical prover code paths.
Overview
Migrates gnark internal logging from the legacy
loggerpackage tolog/slogviainternal/logger, withGNARK_LOG_LEVELdocumented in the README andsloglintenforced in CI (golangci-lint bumped to v2.12.2).Prover/verifier plumbing:
ProverConfigandVerifierConfignow carry a*slog.Logger(defaults fromlogger.Logger()), withWithProverLogger/WithVerifierLoggerand the solver receivingsolver.WithLogger(opt.Logger)during prove. ICICLE Groth16 paths useopt.Logger.With(...)instead of zerolog-style chained loggers.Call-site changes: zerolog patterns (
With().Str().Logger(),.Debug().Msg(),.Dur().Int()) are replaced with slog APIs andlogger.Tracefor verbose GPU/MSM timing; many operational messages are downgraded (e.g. PinToGPU success from info to debug/trace). Groth16 CPU prove/verify and key/proof marshal paths add structured debug logs (duration, bytes, success).Generators: ICICLE Groth16 templates are updated so regenerated curve code matches the new logging style.
Reviewed by Cursor Bugbot for commit f9db470. Bugbot is set up for automated code reviews on this repo. Configure here.