Files
mpc/pkg/logger/logger.go
T
zeekay a4d822eb28 fix(security): Ed25519 initiator verification, proper share verification, no panics
- ConsensusIdentityStore.VerifyInitiatorMessage: implement real Ed25519
  signature verification using the configured event_initiator_pubkey
  instead of blindly accepting all messages
- cggmp21Aggregator.VerifyShare: implement ECDSA partial signature
  verification using secp256k1 curve arithmetic (R' = u1*G + u2*Y_i,
  check R'.x == r mod n) against the party's public key share
- frostAggregator.VerifyShare: implement Schnorr/BIP-340 partial
  signature verification (compute R_i = s_i*G - c*Y_i, verify on curve)
- logger.Error: replace panic on odd keyValues with warning log and
  sentinel value to avoid crashing production
- session.ProcessInboundMessage/ProcessOutboundMessage: replace panics
  with error log and graceful no-op for unoverridden base methods
- eddsaReshareSession: implement ProcessInboundMessage (unmarshal wire
  format, dedup, route to FROST party) and ProcessOutboundMessage (read
  from party Messages channel, wrap in wire format, send)
- cggmp21ReshareSession: implement matching message handlers
- eddsaReshareSession.Reshare: extract actual Ed25519 public key from
  FROST result via GetPublicKeyBytes() instead of empty placeholder
2025-12-27 15:57:11 -08:00

140 lines
3.9 KiB
Go

package logger
import (
"fmt"
"os"
"github.com/rs/zerolog"
"github.com/rs/zerolog/pkgerrors"
)
var Log zerolog.Logger
func Init(env string, debug bool) {
if debug {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
} else {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
if env != "production" {
Log = zerolog.New(
zerolog.ConsoleWriter{Out: os.Stderr, NoColor: false, TimeFormat: "2006-01-02 15:04:05.000"},
).With().Timestamp().Logger()
} else {
Log = zerolog.New(os.Stdout).With().Timestamp().Logger()
}
}
// Debug logs a debug message.
func Debug(msg string, keyValues ...interface{}) {
// ctx needs to be even because it's a series of key/value pairs
// no one wants to check for errors on logging functions,
// so instead of erroring on bad input, we'll just make sure
// that things are the right length and users can fix bugs
// when they see the output looks wrong
l := len(keyValues)
if l%2 != 0 {
Log.Warn().Caller().Interface("Unknown Key", keyValues).Msgf("%s ([Wrong logger.Info usage] Provided args to logger.Info must be a series of key/value pairs)", msg)
} else {
ctx := Log.Debug()
for i := 0; i < len(keyValues); i += 2 {
key, value := keyValues[i].(string), keyValues[i+1]
ctx = ctx.Interface(key, value)
}
ctx.Msg(msg)
}
}
// Info logs an info message.
func Info(msg string, keyValues ...interface{}) {
// ctx needs to be even because it's a series of key/value pairs
// no one wants to check for errors on logging functions,
// so instead of erroring on bad input, we'll just make sure
// that things are the right length and users can fix bugs
// when they see the output looks wrong
l := len(keyValues)
if l%2 != 0 {
Log.Warn().Caller().Interface("Unknown Key", keyValues).Msgf("%s ([Wrong logger.Info usage] Provided args to logger.Info must be a series of key/value pairs)", msg)
} else {
ctx := Log.Info()
for i := 0; i < len(keyValues); i += 2 {
key, value := keyValues[i].(string), keyValues[i+1]
ctx = ctx.Interface(key, value)
}
ctx.Msg(msg)
}
}
func Warn(msg string, keyValues ...interface{}) {
// ctx needs to be even because it's a series of key/value pairs
// no one wants to check for errors on logging functions,
// so instead of erroring on bad input, we'll just make sure
// that things are the right length and users can fix bugs
// when they see the output looks wrong
l := len(keyValues)
if l%2 != 0 {
Log.Warn().Caller().Interface("Unknown Key", keyValues).Msgf("%s ([Wrong logger.Info usage] Provided args to logger.Info must be a series of key/value pairs)", msg)
} else {
ctx := Log.Warn()
for i := 0; i < len(keyValues); i += 2 {
key, value := keyValues[i].(string), keyValues[i+1]
ctx = ctx.Interface(key, value)
}
ctx.Msg(msg)
}
}
// Info logs an info message.
func Infof(format string, v ...interface{}) {
Log.Info().Msgf(format, v...)
}
// Error logs an error message.
func Error(msg string, err error, keyValues ...interface{}) {
if len(keyValues)%2 != 0 {
// Log the malformed call as a warning with all provided args rather
// than panicking, which would crash production. Append a sentinel
// value to make the slice even-length so the loop below still works.
Log.Warn().Caller().Interface("malformedKeyValues", keyValues).
Msg("[logger.Error] keyValues must be a list of key/value pairs; appending sentinel")
keyValues = append(keyValues, "<MISSING_VALUE>")
}
ctx := Log.Error()
for i := 0; i < len(keyValues); i += 2 {
key, ok := keyValues[i].(string)
if !ok {
key = fmt.Sprintf("key_%d", i/2)
}
ctx = ctx.Interface(key, keyValues[i+1])
}
ctx.Caller().Stack().Err(err).Msg(msg)
}
// Fatal logs a fatal message and exits the program.
func Fatal(msg string, err error) {
Log.Fatal().Err(err).Msg(msg)
}
// Panic logs a panic message and panics.
func Panic(msg string, err error) {
Log.Panic().Err(err).Msg(msg)
}