diff --git a/light-clients/lcp/types/lcp.go b/light-clients/lcp/types/lcp.go index 99b05ac..fc2a268 100644 --- a/light-clients/lcp/types/lcp.go +++ b/light-clients/lcp/types/lcp.go @@ -67,12 +67,12 @@ func ComputeChainSalt(chainID string, prefix []byte) common.Hash { return crypto.Keccak256Hash(msg) } -func LCPClientDomain(salt common.Hash) apitypes.TypedDataDomain { +func LCPClientDomain(chainId int64, verifyingContract common.Address, salt common.Hash) apitypes.TypedDataDomain { return apitypes.TypedDataDomain{ Name: "LCPClient", Version: "1", - ChainId: math.NewHexOrDecimal256(0), - VerifyingContract: "0x0000000000000000000000000000000000000000", + ChainId: math.NewHexOrDecimal256(chainId), + VerifyingContract: verifyingContract.Hex(), Salt: salt.Hex(), } } @@ -81,7 +81,7 @@ func GetRegisterEnclaveKeyTypedData(salt common.Hash, avr string) apitypes.Typed return apitypes.TypedData{ PrimaryType: "RegisterEnclaveKey", Types: RegisterEnclaveKeyTypes, - Domain: LCPClientDomain(salt), + Domain: LCPClientDomain(0, common.Address{}, salt), Message: apitypes.TypedDataMessage{ "avr": avr, }, @@ -89,6 +89,8 @@ func GetRegisterEnclaveKeyTypedData(salt common.Hash, avr string) apitypes.Typed } func GetUpdateOperatorsTypedData( + chainId int64, + verifyingContract common.Address, salt common.Hash, clientID string, nonce uint64, @@ -103,7 +105,7 @@ func GetUpdateOperatorsTypedData( return apitypes.TypedData{ PrimaryType: "UpdateOperators", Types: UpdateOperatorsTypes, - Domain: LCPClientDomain(salt), + Domain: LCPClientDomain(chainId, verifyingContract, salt), Message: apitypes.TypedDataMessage{ "clientId": clientID, "nonce": fmt.Sprint(nonce), @@ -134,7 +136,7 @@ func ComputeEIP712RegisterEnclaveKeyHash(chainID string, prefix []byte, report s return crypto.Keccak256Hash(bz), nil } -func ComputeEIP712UpdateOperators( +func ComputeEIP712UpdateOperatorsCosmos( chainID string, prefix []byte, clientID string, @@ -143,10 +145,12 @@ func ComputeEIP712UpdateOperators( newOperatorThresholdNumerator uint64, newOperatorThresholdDenominator uint64, ) ([]byte, error) { - return ComputeEIP712UpdateOperatorsWithSalt(ComputeChainSalt(chainID, prefix), clientID, nonce, newOperators, newOperatorThresholdNumerator, newOperatorThresholdDenominator) + return ComputeEIP712UpdateOperators(0, common.Address{}, ComputeChainSalt(chainID, prefix), clientID, nonce, newOperators, newOperatorThresholdNumerator, newOperatorThresholdDenominator) } -func ComputeEIP712UpdateOperatorsWithSalt( +func ComputeEIP712UpdateOperators( + chainId int64, + verifyingContract common.Address, salt common.Hash, clientID string, nonce uint64, @@ -155,7 +159,7 @@ func ComputeEIP712UpdateOperatorsWithSalt( newOperatorThresholdDenominator uint64, ) ([]byte, error) { _, raw, err := apitypes.TypedDataAndHash( - GetUpdateOperatorsTypedData(salt, clientID, nonce, newOperators, newOperatorThresholdNumerator, newOperatorThresholdDenominator), + GetUpdateOperatorsTypedData(chainId, verifyingContract, salt, clientID, nonce, newOperators, newOperatorThresholdNumerator, newOperatorThresholdDenominator), ) if err != nil { return nil, err diff --git a/light-clients/lcp/types/update.go b/light-clients/lcp/types/update.go index f0c0a11..b023ca4 100644 --- a/light-clients/lcp/types/update.go +++ b/light-clients/lcp/types/update.go @@ -175,7 +175,7 @@ func (cs ClientState) verifyUpdateOperators(ctx sdk.Context, store storetypes.KV return errorsmod.Wrapf(clienttypes.ErrInvalidHeader, "operator addresses must be ordered: clientID=%v op0=%v op1=%v", clientID, newOperators[i-1].String(), op.String()) } } - signBytes, err := ComputeEIP712UpdateOperators( + signBytes, err := ComputeEIP712UpdateOperatorsCosmos( ctx.ChainID(), []byte(exported.StoreKey), clientID, diff --git a/relay/lcp.go b/relay/lcp.go index 75302db..bfb3479 100644 --- a/relay/lcp.go +++ b/relay/lcp.go @@ -371,13 +371,26 @@ func (pr *Prover) ComputeEIP712RegisterEnclaveKeyHash(report string) (common.Has } func (pr *Prover) ComputeEIP712UpdateOperatorsHash(nonce uint64, newOperators []common.Address, thresholdNumerator, thresholdDenominator uint64) (common.Hash, error) { - bz, err := lcptypes.ComputeEIP712UpdateOperatorsWithSalt(pr.computeEIP712ChainSalt(), pr.path.ClientID, nonce, newOperators, thresholdNumerator, thresholdDenominator) + chainId, verifyingContract := pr.getDomainParams() + bz, err := lcptypes.ComputeEIP712UpdateOperators(chainId, verifyingContract, pr.computeEIP712ChainSalt(), pr.path.ClientID, nonce, newOperators, thresholdNumerator, thresholdDenominator) if err != nil { return common.Hash{}, err } return crypto.Keccak256Hash(bz), nil } +func (pr *Prover) getDomainParams() (int64, common.Address) { + switch pr.config.ChainType() { + case ChainTypeEVM: + salt := pr.config.GetEvmChainEip712Salt() + return int64(salt.ChainId), common.HexToAddress(salt.VerifyingContractAddress) + case ChainTypeCosmos: + return 0, common.Address{} + default: + panic(fmt.Sprintf("unsupported chain type: %v", pr.config.ChainType())) + } +} + func (pr *Prover) computeEIP712ChainSalt() common.Hash { switch pr.config.ChainType() { case ChainTypeEVM: