Skip to content

Commit

Permalink
improve prover config validation
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Jun 21, 2024
1 parent 11101a9 commit 7fe3bd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions relay/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
7 changes: 6 additions & 1 deletion relay/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand Down

0 comments on commit 7fe3bd5

Please sign in to comment.