Skip to content

feat: implement slog-based logging#1769

Open
ivokub wants to merge 45 commits into
masterfrom
feat/slog-rebased
Open

feat: implement slog-based logging#1769
ivokub wants to merge 45 commits into
masterfrom
feat/slog-rebased

Conversation

@ivokub

@ivokub ivokub commented May 20, 2026

Copy link
Copy Markdown
Collaborator

Description

Start migration to log/slog which is a structured logger in standard library. Currently still backwards compatible, but will remove the logger package in the future to only provide entry points during compile, solve, prove and verify to plug in custom handlers.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How has this been tested?

  • Test A
  • Test B

How has this been benchmarked?

  • Benchmark A, on Macbook pro M1, 32GB RAM
  • Benchmark B, on x86 Intel xxx, 16GB RAM

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I did not modify files generated from templates
  • golangci-lint does not output errors locally
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Note

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 logger package to log/slog via internal/logger, with GNARK_LOG_LEVEL documented in the README and sloglint enforced in CI (golangci-lint bumped to v2.12.2).

Prover/verifier plumbing: ProverConfig and VerifierConfig now carry a *slog.Logger (defaults from logger.Logger()), with WithProverLogger / WithVerifierLogger and the solver receiving solver.WithLogger(opt.Logger) during prove. ICICLE Groth16 paths use opt.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 and logger.Trace for 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.

ivokub added 30 commits May 19, 2026 23:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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) with GNARK_LOG_LEVEL configuration and a zerolog compatibility adapter.
  • Thread *slog.Logger through frontend compilation, constraint solving, and backend prover/verifier configs (including templates and accelerated/icicle paths).
  • Deprecate the public logger package 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.

Comment thread internal/logger/logger.go
Comment thread internal/compilelogger/compilelogger.go
Comment thread internal/compilelogger/compilelogger.go
Comment thread std/rangecheck/rangecheck_commit.go
@ivokub ivokub marked this pull request as ready for review May 21, 2026 09:44
@ivokub ivokub requested a review from Copilot May 21, 2026 09:44
Comment thread backend/accelerated/icicle/internal/generator/templates/groth16.icicle.go.tmpl Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread constraint/solver/options.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread frontend/builder.go
Comment thread backend/backend.go
@ivokub

ivokub commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

@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.

time=2026-06-11T10:56:22.969Z level=DEBUG source=/home/ubuntu/src/gnark/internal/logger/logger.go:123 msg="runtime configuration" gomaxprocs=8 gomemlimit=∞ goarch=amd64 goos=linux support_neon=false support_avx512=f
alse support_avx512ifma=false gnark_version=0.15.0 build_tags=icicle go_build_version=go1.25.7 vcs_tagged_version=(devel) vcs_modified=""

I would say biggest difference is that now api.Println doesn't have custom handling, so the printed lines are a la https://github.com/Consensys/gnark/pull/1769/changes#diff-cd33dcd5c0776ca721b2b7bde44cffa80109541b9cdb11c2fe35c5a9d6cac275L51-R55. In principle I could have a custom handler to avoid printing fields etc, but I wanted to keep compatible with native TextHandler.

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 debug is set. But the env value always overrides even the build tag).

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