Skip to content

Commit

Permalink
move ChainType into lc types
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Jun 17, 2024
1 parent 2f3a03a commit 22451ea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
22 changes: 20 additions & 2 deletions light-clients/lcp/types/lcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const (
QuoteSwHardeningNeeded = "SW_HARDENING_NEEDED"
QuoteConfigurationAndSwHardeningNeeded = "CONFIGURATION_AND_SW_HARDENING_NEEDED"

ChainTypeCosmos uint16 = 2
ChainTypeEVM ChainType = 1
ChainTypeCosmos ChainType = 2
)

var (
Expand Down Expand Up @@ -58,9 +59,26 @@ var (
}
)

type ChainType uint16

func (t ChainType) String() string {
switch t {
case ChainTypeEVM:
return "EVM"
case ChainTypeCosmos:
return "Cosmos"
default:
return fmt.Sprintf("UnknownChainType(%d)", t.Uint16())
}
}

func (t ChainType) Uint16() uint16 {
return uint16(t)
}

func ComputeChainSalt(chainID string, prefix []byte) common.Hash {
msg := make([]byte, 2)
binary.BigEndian.PutUint16(msg, ChainTypeCosmos)
binary.BigEndian.PutUint16(msg, ChainTypeCosmos.Uint16())
// TODO abi encode?
msg = append(msg, []byte(chainID)...)
msg = append(msg, prefix...)
Expand Down
26 changes: 3 additions & 23 deletions relay/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,8 @@ import (
const (
DefaultDialTimeout = 20 // seconds
DefaultMessageAggregationBatchSize = 8

ChainTypeEVM ChainType = 1
ChainTypeCosmos ChainType = 2
)

type ChainType uint16

func (t ChainType) String() string {
switch t {
case ChainTypeEVM:
return "EVM"
case ChainTypeCosmos:
return "Cosmos"
default:
return fmt.Sprintf("UnknownChainType(%d)", t.Uint16())
}
}

func (t ChainType) Uint16() uint16 {
return uint16(t)
}

var _ core.ProverConfig = (*ProverConfig)(nil)

var _ codectypes.UnpackInterfacesMessage = (*ProverConfig)(nil)
Expand Down Expand Up @@ -92,12 +72,12 @@ func (pc ProverConfig) GetMessageAggregationBatchSize() uint64 {
}
}

func (pc ProverConfig) ChainType() ChainType {
func (pc ProverConfig) ChainType() lcptypes.ChainType {
switch pc.OperatorsEip712Params.(type) {
case *ProverConfig_OperatorsEvmChainEip712Params:
return ChainTypeEVM
return lcptypes.ChainTypeEVM
case *ProverConfig_OperatorsCosmosChainEip712Params:
return ChainTypeCosmos
return lcptypes.ChainTypeCosmos
default:
panic(fmt.Sprintf("unknown chain params: %v", pc.OperatorsEip712Params))
}
Expand Down
10 changes: 5 additions & 5 deletions relay/lcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,13 @@ func (pr *Prover) ComputeEIP712UpdateOperatorsHash(nonce uint64, newOperators []

func (pr *Prover) getDomainParams() EIP712DomainParams {
switch pr.config.ChainType() {
case ChainTypeEVM:
case lcptypes.ChainTypeEVM:
params := pr.config.GetOperatorsEvmChainEip712Params()
return EIP712DomainParams{
ChainId: params.ChainId,
VerifyingContractAddr: common.HexToAddress(params.VerifyingContractAddress),
}
case ChainTypeCosmos:
case lcptypes.ChainTypeCosmos:
return EIP712DomainParams{
ChainId: 0,
VerifyingContractAddr: common.Address{},
Expand All @@ -448,9 +448,9 @@ func (pr *Prover) getDomainParams() EIP712DomainParams {

func (pr *Prover) computeEIP712ChainSalt() common.Hash {
switch pr.config.ChainType() {
case ChainTypeEVM:
case lcptypes.ChainTypeEVM:
return pr.computeEIP712EVMChainSalt()
case ChainTypeCosmos:
case lcptypes.ChainTypeCosmos:
return pr.computeEIP712CosmosChainSalt()
default:
panic(fmt.Sprintf("unsupported chain type: %v", pr.config.ChainType()))
Expand All @@ -459,7 +459,7 @@ func (pr *Prover) computeEIP712ChainSalt() common.Hash {

func (pr *Prover) computeEIP712EVMChainSalt() common.Hash {
var bz [2]byte
binary.BigEndian.PutUint16(bz[:], ChainTypeEVM.Uint16())
binary.BigEndian.PutUint16(bz[:], lcptypes.ChainTypeEVM.Uint16())
return crypto.Keccak256Hash(bz[:])
}

Expand Down

0 comments on commit 22451ea

Please sign in to comment.