Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
additional changes from diff
Browse files Browse the repository at this point in the history
  • Loading branch information
fedekunze committed Nov 1, 2022
1 parent 58205ac commit 1699efb
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 25 deletions.
19 changes: 0 additions & 19 deletions ethereum/eip712/eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,9 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
)

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

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

rawData := []byte(fmt.Sprintf("\x19\x01%s%s", string(domainSeparator), string(typedDataHash)))
return crypto.Keccak256(rawData), nil
}

// WrapTxToTypedData is an ultimate method that wraps Amino-encoded Cosmos Tx JSON data
// into an EIP712-compatible TypedData request.
func WrapTxToTypedData(
Expand Down
3 changes: 3 additions & 0 deletions rpc/backend/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ func (b *Backend) FeeHistory(
}
blockEnd = int64(blockNumber)
}

userBlockCountInt := int64(userBlockCount)
maxBlockCount := int64(b.cfg.JSONRPC.FeeHistoryCap)
if userBlockCountInt > maxBlockCount {
return nil, fmt.Errorf("FeeHistory user block count %d higher than %d", userBlockCountInt, maxBlockCount)
}

blockStart := blockEnd - userBlockCountInt
if blockStart < 0 {
blockStart = 0
Expand All @@ -173,6 +175,7 @@ func (b *Backend) FeeHistory(
for i := 0; i < int(blockCount); i++ {
reward[i] = make([]*hexutil.Big, rewardCount)
}

thisBaseFee := make([]*hexutil.Big, blockCount)
thisGasUsedRatio := make([]float64, blockCount)

Expand Down
8 changes: 5 additions & 3 deletions rpc/backend/sign_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import (
"fmt"
"math/big"

"github.com/pkg/errors"

"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
"github.com/evmos/ethermint/ethereum/eip712"

evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/pkg/errors"
)

// SendTransaction sends transaction based on received args using Node's key to sign it
Expand Down Expand Up @@ -135,7 +137,7 @@ func (b *Backend) SignTypedData(address common.Address, typedData apitypes.Typed
return nil, fmt.Errorf("%s; %s", keystore.ErrNoMatch, err.Error())
}

sigHash, err := eip712.ComputeTypedDataHash(typedData)
sigHash, _, err := apitypes.TypedDataAndHash(typedData)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion rpc/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
BlockParamEarliest = "earliest"
BlockParamLatest = "latest"
BlockParamFinalized = "finalized"
BlockParamSafe = "safe"
BlockParamPending = "pending"
)

Expand Down Expand Up @@ -73,7 +74,7 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
case BlockParamEarliest:
*bn = EthEarliestBlockNumber
return nil
case BlockParamLatest, BlockParamFinalized:
case BlockParamLatest, BlockParamFinalized, BlockParamSafe:
*bn = EthLatestBlockNumber
return nil
case BlockParamPending:
Expand Down
5 changes: 3 additions & 2 deletions x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
return nil, sdkerrors.Wrap(types.ErrGasOverflow, "apply message")
}
// refund gas
leftoverGas += GasToRefund(stateDB.GetRefund(), msg.Gas()-leftoverGas, refundQuotient)
temporaryGasUsed := msg.Gas() - leftoverGas
leftoverGas += GasToRefund(stateDB.GetRefund(), temporaryGasUsed, refundQuotient)

// EVM execution error needs to be available for the JSON-RPC client
var vmError string
Expand All @@ -448,7 +449,7 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
if msg.Gas() < leftoverGas {
return nil, sdkerrors.Wrapf(types.ErrGasOverflow, "message gas limit < leftover gas (%d < %d)", msg.Gas(), leftoverGas)
}
temporaryGasUsed := msg.Gas() - leftoverGas

gasUsed := sdk.MaxDec(minimumGasUsed, sdk.NewDec(int64(temporaryGasUsed))).TruncateInt().Uint64()
// reset leftoverGas, to be used by the tracer
leftoverGas = msg.Gas() - gasUsed
Expand Down
2 changes: 2 additions & 0 deletions x/evm/types/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func (cc ChainConfig) EthereumConfig(chainID *big.Int) *params.ChainConfig {
ArrowGlacierBlock: getBlockValue(cc.ArrowGlacierBlock),
GrayGlacierBlock: getBlockValue(cc.GrayGlacierBlock),
MergeNetsplitBlock: getBlockValue(cc.MergeNetsplitBlock),
ShanghaiBlock: nil, // TODO: add shanghai block
CancunBlock: nil, // TODO: add cancun block
TerminalTotalDifficulty: nil,
Ethash: nil,
Clique: nil,
Expand Down

0 comments on commit 1699efb

Please sign in to comment.