Skip to content

Commit

Permalink
wip: add cdp signers
Browse files Browse the repository at this point in the history
  • Loading branch information
boodyvo committed Nov 5, 2024
1 parent 46860cc commit 2b40405
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 51 deletions.
26 changes: 0 additions & 26 deletions ethereum/eip712/eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,15 @@ func ConstructUntypedEIP712Data(
panic(err)
}

fmt.Println("ConstructUntypedEIP712Data inInterface", inInterface)

for _, msg := range msgs {
bz := legacytx.RegressionTestingAminoCodec.MustMarshalJSON(msg)
fmt.Println("ConstructUntypedEIP712Data bz for msg: ", msg)
fmt.Println("ConstructUntypedEIP712Data bz for msg: ", bz)
fmt.Println("ConstructUntypedEIP712Data bz for msg: ", sdk.MustSortJSON(bz))
}

// remove msgs from the sign doc since we will be adding them as separate fields
delete(inInterface, "msgs")

// Add messages as separate fields
for i := 0; i < len(msgs); i++ {
fmt.Println("ConstructUntypedEIP712Data msg", msgs[i])
msg := msgs[i]

bz := legacytx.RegressionTestingAminoCodec.MustMarshalJSON(msg)
fmt.Println("ConstructUntypedEIP712Data bz", bz)
msgBytes := sdk.MustSortJSON(bz)
fmt.Println("ConstructUntypedEIP712Data msgBytes", json.RawMessage(msgBytes))

//legacyMsg, ok := msg.(legacytx.LegacyMsg)
//if !ok {
Expand Down Expand Up @@ -185,32 +173,18 @@ func EncodeData(typedData apitypes.TypedData, primaryType string, data map[strin

// ComputeTypedDataHash computes keccak hash of typed data for signing.
func ComputeTypedDataHash(typedData apitypes.TypedData) ([]byte, error) {
fmt.Println("ComputeTypedDataHash", typedData)
domainSeparator, err := typedData.HashStruct("EIP712Domain", typedData.Domain.Map())
if err != nil {
err = errorsmod.Wrap(err, "failed to pack and hash typedData EIP712Domain")
return nil, err
}

fmt.Println("domainSeparator", domainSeparator)
fmt.Println("typedData.PrimaryType", typedData.PrimaryType)
fmt.Println("typedData.Message", typedData.Message)

fmt.Println("before encoding")

//encodedData, err := typedData.EncodeData(typedData.PrimaryType, typedData.Message, 1)
encodedData, err := EncodeData(typedData, typedData.PrimaryType, typedData.Message, 1)
fmt.Println("encodedData", encodedData)
fmt.Println("err", err)

typedDataHash, err := typedData.HashStruct(typedData.PrimaryType, typedData.Message)
if err != nil {
err = errorsmod.Wrap(err, "failed to pack and hash typedData primary type")
return nil, err
}

fmt.Println("typedDataHash", typedDataHash)

rawData := []byte(fmt.Sprintf("\x19\x01%s%s", string(domainSeparator), string(typedDataHash)))
return crypto.Keccak256(rawData), nil
}
Expand Down
1 change: 1 addition & 0 deletions rpc/backend/call_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ func (b *Backend) DoCall(

// GasPrice returns the current gas price based on Ethermint's gas price oracle.
func (b *Backend) GasPrice() (*hexutil.Big, error) {
fmt.Println("Backend GasPrice")
var (
result *big.Int
err error
Expand Down
2 changes: 2 additions & 0 deletions rpc/namespaces/ethereum/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package eth

import (
"context"
"fmt"

"github.com/ethereum/go-ethereum/signer/core/apitypes"

Expand Down Expand Up @@ -313,6 +314,7 @@ func (e *PublicAPI) ProtocolVersion() hexutil.Uint {

// GasPrice returns the current gas price based on Ethermint's gas price oracle.
func (e *PublicAPI) GasPrice() (*hexutil.Big, error) {
fmt.Println("GasPrice eth_gasPrice")
e.logger.Debug("eth_gasPrice")
return e.backend.GasPrice()
}
Expand Down
1 change: 1 addition & 0 deletions x/evm/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func InitGenesis(
}

isEnabledPrecompile := make(map[string]struct{})
fmt.Println("eth evm genesis InitGenesis gs.Params.EnabledPrecompiles", data.Params.EnabledPrecompiles)
for _, ep := range data.Params.EnabledPrecompiles {
isEnabledPrecompile[ep] = struct{}{}
}
Expand Down
2 changes: 2 additions & 0 deletions x/evm/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func (gs GenesisState) Validate() error {
return fmt.Errorf("invalid params: %w", err)
}

fmt.Println("eth types genesis Validate gs.Params.EnabledPrecompiles", gs.Params.EnabledPrecompiles)

for _, ep := range gs.Params.EnabledPrecompiles {
if _, ok := seenAccounts[ep]; !ok {
return fmt.Errorf("enabled precompile %s must have a matching genesis account", ep)
Expand Down
25 changes: 0 additions & 25 deletions x/evm/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,31 +277,6 @@ func (msg *MsgEthereumTx) GetSigners() ([][]byte, error) {
return [][]byte{signer}, nil
}

// func (pc ProtoCodec) GetMsgAnySigners(msg *types.Any) ([][]byte, proto.Message, error) {
// msgv2, err := anyutil.Unpack(&anypb.Any{
// TypeUrl: msg.TypeUrl,
// Value: msg.Value,
// }, pc.interfaceRegistry, nil)
// if err != nil {
// return nil, nil, err
// }
//
// signers, err := pc.interfaceRegistry.SigningContext().GetSigners(msgv2)
// return signers, msgv2, err
//}

//func (pc *ProtoCodec) GetMsgV1Signers(msg gogoproto.Message) ([][]byte, proto.Message, error) {
// if msgV2, ok := msg.(proto.Message); ok {
// signers, err := pc.interfaceRegistry.SigningContext().GetSigners(msgV2)
// return signers, msgV2, err
// }
// a, err := types.NewAnyWithValue(msg)
// if err != nil {
// return nil, nil, err
// }
// return pc.GetMsgAnySigners(a)
//}

// TODO(boodyvo): implement this method
// func(proto.Message) ([][]byte, error)
func GetSigners(msg protov2.Message) ([][]byte, error) {
Expand Down

0 comments on commit 2b40405

Please sign in to comment.