From 7fe3bd50fe60c54b2a79fc98a69c2472dd75c284 Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Fri, 21 Jun 2024 11:13:17 +0900 Subject: [PATCH] improve prover config validation Signed-off-by: Jun Kimura --- relay/config.go | 6 ++++-- relay/operator.go | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/relay/config.go b/relay/config.go index 0019773..cb07664 100644 --- a/relay/config.go +++ b/relay/config.go @@ -106,10 +106,12 @@ func (pc ProverConfig) Validate() error { if l := len(pc.Operators); l > 1 { return fmt.Errorf("Operators: currently only one or zero(=permissionless) operator is supported, but got %v", l) } - if pc.OperatorsEip712Params != nil { + if len(pc.Operators) > 0 || pc.OperatorsEip712Params != nil { if pc.OperatorSigner == nil { - return fmt.Errorf("OperatorSigner must be set if OperatorsEip712Params is set") + return fmt.Errorf("OperatorSigner must be set if Operators or OperatorsEip712Params is set") } + } + if pc.OperatorsEip712Params != nil { signerConfig, ok := pc.OperatorSigner.GetCachedValue().(signer.SignerConfig) if !ok { return fmt.Errorf("failed to cast OperatorSigner's config: %T", pc.OperatorSigner.GetCachedValue()) diff --git a/relay/operator.go b/relay/operator.go index caceb1a..c3fc621 100644 --- a/relay/operator.go +++ b/relay/operator.go @@ -17,7 +17,7 @@ import ( ) func (pr *Prover) IsOperatorEnabled() bool { - return pr.eip712Signer != nil && pr.config.OperatorsEip712Params != nil + return len(pr.config.Operators) > 0 } func (pr *Prover) GetOperators() ([]common.Address, error) { @@ -41,6 +41,11 @@ func (pr *Prover) GetOperatorsThreshold() Fraction { } func (pr *Prover) updateOperators(counterparty core.Chain, nonce uint64, newOperators []common.Address, threshold Fraction) error { + if !pr.IsOperatorEnabled() { + return fmt.Errorf("operator is not enabled") + } else if pr.config.OperatorsEip712Params == nil { + return fmt.Errorf("operator EIP712 parameters are not set") + } if nonce == 0 { return fmt.Errorf("invalid nonce: %v", nonce) }