Skip to content
Merged
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
38 changes: 28 additions & 10 deletions op-batcher/batcher/espresso_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,31 @@ func (bs *BatcherService) EspressoStreamer() *espressoStreamers.Streamer {
return bs.driver.espressoStreamer
}

// initChainSigner asserts that the configured TxManager implements the
// ChainSigner interface and stores the embedded ChainSigner on the service.
// Espresso uses ChainSigner to sign batch authentication payloads sent to the
// BatchAuthenticator contract; the cast is required by every Espresso path.
// initChainSigner builds the ChainSigner that signs the Espresso transaction
// envelope (see EspressoBatch.ToEspressoTransaction), from the same signing config
// the txmgr uses. Distinct from the enclave key pair, which signs the EIP-712
// commitment BatchAuthenticator verifies.
func (bs *BatcherService) initChainSigner(cfg *CLIConfig) error {
if !cfg.Espresso.Enabled {
return nil
tcfg := cfg.TxMgrConfig

// Same HD-path resolution as txmgr.NewConfig.
hdPath := tcfg.HDPath
if hdPath == "" && tcfg.SequencerHDPath != "" {
hdPath = tcfg.SequencerHDPath
} else if hdPath == "" && tcfg.L2OutputHDPath != "" {
hdPath = tcfg.L2OutputHDPath
}
cast, castOk := bs.TxManager.(opcrypto.ChainSigner)
if !castOk {
return fmt.Errorf("tx manager does not implement ChainSigner")

factory, from, err := opcrypto.ChainSignerFactoryFromConfig(bs.Log, tcfg.PrivateKey, tcfg.Mnemonic, hdPath, tcfg.SignerCLIConfig)
if err != nil {
return fmt.Errorf("failed to init Espresso chain signer: %w", err)
}
bs.ChainSigner = cast
if txFrom := bs.TxManager.From(); from != txFrom {
return fmt.Errorf(
"espresso chain signer resolved to %s but the txmgr sends from %s: the two "+
"derivations of the same signing config have diverged", from, txFrom)
}
bs.ChainSigner = factory(bs.TxManager.ChainID().ToBig(), from)
return nil
}

Expand Down Expand Up @@ -154,6 +166,12 @@ func (bs *BatcherService) initEspresso(ctx context.Context, cfg *CLIConfig) erro
}
bs.EspressoLightClient = lightClient

// Two distinct signing identities: the L1 batcher key below, and the ephemeral
// enclave key after it.
if err := bs.initChainSigner(cfg); err != nil {
return err
}

if err := bs.initKeyPair(); err != nil {
return fmt.Errorf("failed to create key pair for batcher: %w", err)
}
Expand Down
3 changes: 0 additions & 3 deletions op-batcher/batcher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,6 @@ func (bs *BatcherService) initTxManager(_ context.Context, cfg *CLIConfig) error
return err
}
bs.TxManager = txManager
if err := bs.initChainSigner(cfg); err != nil {
return err
}
return nil
}

Expand Down
5 changes: 5 additions & 0 deletions op-service/crypto/espresso.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ var _ ChainSigner = &privateKeySigner{}
// ChainSignerFactoryFromConfig considers three ways that signers are created & then creates single factory from those config options.
// It can either take a remote signer (via opsigner.CLIConfig) or it can be provided either a mnemonic + derivation path or a private key.
// It prefers the remote signer, then the mnemonic or private key (only one of which can be provided).
//
// Duplicates the key resolution in SignerFactoryFromConfig (signature.go) rather
// than wrapping it: SignerFactory yields a SignerFn, which signs transactions only,
// while ChainSigner also needs Sign over an arbitrary hash. txmgr uses the former,
// Espresso the latter; neither is redundant.
func ChainSignerFactoryFromConfig(l log.Logger, privateKey, mnemonic, hdPath string, signerConfig opsigner.CLIConfig) (ChainSignerFactory, common.Address, error) {
var signer ChainSignerFactory
var fromAddress common.Address
Expand Down
10 changes: 2 additions & 8 deletions op-service/txmgr/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func NewConfig(cfg CLIConfig, l log.Logger) (*Config, error) {
hdPath = cfg.L2OutputHDPath
}

chainSignerFactory, from, err := opcrypto.ChainSignerFactoryFromConfig(l, cfg.PrivateKey, cfg.Mnemonic, hdPath, cfg.SignerCLIConfig)
signerFactory, from, err := opcrypto.SignerFactoryFromConfig(l, cfg.PrivateKey, cfg.Mnemonic, hdPath, cfg.SignerCLIConfig)
if err != nil {
return nil, fmt.Errorf("could not init signer: %w", err)
}
Expand Down Expand Up @@ -527,16 +527,13 @@ func NewConfig(cfg CLIConfig, l log.Logger) (*Config, error) {
}

cellProofTime := fallbackToOsakaCellProofTimeIfKnown(chainID, cfg.CellProofTime)
chainSigner := chainSignerFactory(chainID, from)

res := Config{
Backend: l1,
ChainID: chainID,
Signer: chainSigner.SignTransaction,
Signer: signerFactory(chainID),
From: from,

ChainSigner: chainSigner,

TxSendTimeout: cfg.TxSendTimeout,
TxNotInMempoolTimeout: cfg.TxNotInMempoolTimeout,
NetworkTimeout: cfg.NetworkTimeout,
Expand Down Expand Up @@ -667,9 +664,6 @@ type Config struct {
Signer opcrypto.SignerFn
From common.Address

// ChainSigner is used to allow for easy signing of transactions and arbitrary data.
ChainSigner opcrypto.ChainSigner

// GasPriceEstimatorFn is used to estimate the gas price for a transaction.
// If nil, DefaultGasPriceEstimatorFn is used.
GasPriceEstimatorFn GasPriceEstimatorFn
Expand Down
22 changes: 0 additions & 22 deletions op-service/txmgr/espresso.go

This file was deleted.