Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(evm)!: Refactor out dead code from the evm.Params #2065

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#2054](https://github.com/NibiruChain/nibiru/pull/2054) - feat(evm-precompile): Precompile for one-way EVM calls to invoke/execute Wasm contracts.
- [#2060](https://github.com/NibiruChain/nibiru/pull/2060) - fix(evm-precompiles): add assertNumArgs validation
- [#2056](https://github.com/NibiruChain/nibiru/pull/2056) - feat(evm): add oracle precompile
- [#2065](https://github.com/NibiruChain/nibiru/pull/2065) - refactor(evm)!: Refactor out dead code from the evm.Params


#### Dapp modules: perp, spot, oracle, etc

Expand Down
10 changes: 6 additions & 4 deletions app/evmante/evmante_gas_consume.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ func (anteDec AnteDecEthGasConsume) AnteHandle(
return next(newCtx, tx, simulate)
}

evmParams := anteDec.evmKeeper.GetParams(ctx)
evmDenom := evmParams.GetEvmDenom()

var events sdk.Events

// Use the lowest priority of all the messages as the final one.
Expand Down Expand Up @@ -100,7 +97,12 @@ func (anteDec AnteDecEthGasConsume) AnteHandle(
gasWanted += txData.GetGas()
}

fees, err := keeper.VerifyFee(txData, evmDenom, baseFeeMicronibiPerGas, ctx.IsCheckTx())
fees, err := keeper.VerifyFee(
txData,
evm.EVMBankDenom,
baseFeeMicronibiPerGas,
ctx.IsCheckTx(),
)
if err != nil {
return ctx, errors.Wrapf(err, "failed to verify the fees")
}
Expand Down
2 changes: 1 addition & 1 deletion app/evmante/evmante_mempool_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (d MempoolGasPriceDecorator) AnteHandle(
return next(ctx, tx, simulate)
}

minGasPrice := ctx.MinGasPrices().AmountOf(d.evmKeeper.GetParams(ctx).EvmDenom)
minGasPrice := ctx.MinGasPrices().AmountOf(evm.EVMBankDenom)
baseFeeMicronibi := d.evmKeeper.GetBaseFee(ctx)
baseFeeDec := math.LegacyNewDecFromBigInt(baseFeeMicronibi)

Expand Down
3 changes: 1 addition & 2 deletions app/evmante/evmante_sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func (esvd EthSigVerificationDecorator) AnteHandle(
ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler,
) (newCtx sdk.Context, err error) {
chainID := esvd.evmKeeper.EthChainID(ctx)
evmParams := esvd.evmKeeper.GetParams(ctx)
ethCfg := evm.EthereumConfig(chainID)
blockNum := big.NewInt(ctx.BlockHeight())
signer := gethcore.MakeSigner(ethCfg, blockNum)
Expand All @@ -48,7 +47,7 @@ func (esvd EthSigVerificationDecorator) AnteHandle(
)
}

allowUnprotectedTxs := evmParams.GetAllowUnprotectedTxs()
allowUnprotectedTxs := false
ethTx := msgEthTx.AsTransaction()
if !allowUnprotectedTxs && !ethTx.Protected() {
return ctx, errors.Wrapf(
Expand Down
4 changes: 1 addition & 3 deletions app/evmante/evmante_validate_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
txFee := sdk.Coins{}
txGasLimit := uint64(0)

evmParams := vbd.evmKeeper.GetParams(ctx)
baseFee := vbd.evmKeeper.GetBaseFee(ctx)
evmDenom := evmParams.GetEvmDenom()

for _, msg := range protoTx.GetMsgs() {
msgEthTx, ok := msg.(*evm.MsgEthereumTx)
Expand Down Expand Up @@ -126,7 +124,7 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu

txFee = txFee.Add(
sdk.Coin{
Denom: evmDenom,
Denom: evm.EVMBankDenom,
Amount: sdkmath.NewIntFromBigInt(txData.Fee()),
},
)
Expand Down
2 changes: 1 addition & 1 deletion eth/eip712/eip712_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestEIP712TestSuite(t *testing.T) {
func (suite *EIP712TestSuite) SetupTest() {
suite.config = encoding.MakeConfig(app.ModuleBasics)
suite.clientCtx = client.Context{}.WithTxConfig(suite.config.TxConfig)
suite.denom = evm.DefaultEVMDenom
suite.denom = evm.EVMBankDenom

sdk.GetConfig().SetBech32PrefixForAccount(appconst.AccountAddressPrefix, "")
eip712.SetEncodingConfig(suite.config)
Expand Down
9 changes: 1 addition & 8 deletions eth/rpc/backend/call_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,7 @@ func (b *Backend) SendRawTransaction(data hexutil.Bytes) (common.Hash, error) {
return common.Hash{}, err
}

// Query params to use the EVM denomination
res, err := b.queryClient.QueryClient.Params(b.ctx, &evm.QueryParamsRequest{})
if err != nil {
b.logger.Error("failed to query evm params", "error", err.Error())
return common.Hash{}, err
}

cosmosTx, err := ethereumTx.BuildTx(b.clientCtx.TxConfig.NewTxBuilder(), res.Params.EvmDenom)
cosmosTx, err := ethereumTx.BuildTx(b.clientCtx.TxConfig.NewTxBuilder(), evm.EVMBankDenom)
if err != nil {
b.logger.Error("failed to build cosmos tx", "error", err.Error())
return common.Hash{}, err
Expand Down
7 changes: 1 addition & 6 deletions eth/rpc/backend/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,8 @@ func (b *Backend) RPCBlockRangeCap() int32 {
// RPCMinGasPrice returns the minimum gas price for a transaction obtained from
// the node config. If set value is 0, it will default to 20.
func (b *Backend) RPCMinGasPrice() int64 {
evmParams, err := b.queryClient.Params(b.ctx, &evm.QueryParamsRequest{})
if err != nil {
return eth.DefaultGasPrice
}

minGasPrice := b.cfg.GetMinGasPrices()
amt := minGasPrice.AmountOf(evmParams.Params.EvmDenom).TruncateInt64()
amt := minGasPrice.AmountOf(evm.EVMBankDenom).TruncateInt64()
if amt == 0 {
return eth.DefaultGasPrice
}
Expand Down
3 changes: 1 addition & 2 deletions eth/rpc/rpcapi/eth_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ func (s *NodeSuite) Test_SimpleTransferTransaction() {
pendingEthTxEventIndex := int32(-1)
for _, event := range events {
if event.Type == evm.PendingEthereumTxEvent {
pendingEthTxEventHash, pendingEthTxEventIndex, err =
evm.GetEthHashAndIndexFromPendingEthereumTxEvent(event)
pendingEthTxEventHash, pendingEthTxEventIndex, err = evm.GetEthHashAndIndexFromPendingEthereumTxEvent(event)
s.Require().NoError(err)
}
if event.Type == evm.TypeUrlEventEthereumTx {
Expand Down
11 changes: 5 additions & 6 deletions proto/eth/evm/v1/evm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
}

// Params defines the EVM module parameters
message Params {

Check failure on line 30 in proto/eth/evm/v1/evm.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present field "1" with name "evm_denom" on message "Params" was deleted.

Check failure on line 30 in proto/eth/evm/v1/evm.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present field "6" with name "allow_unprotected_txs" on message "Params" was deleted.
option (gogoproto.equal) = true;
// evm_denom represents the token denomination used to run the EVM state
// transitions.
string evm_denom = 1 [ (gogoproto.moretags) = "yaml:\"evm_denom\"" ];
// DEPRECATED: evm_denom
reserved 1;
Comment on lines +32 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

EvmDenom constant not found

The EvmDenom constant definition was not found in the codebase. Please ensure that EvmDenom is defined as a constant to align with the PR objectives.

🔗 Analysis chain

Approve deprecation of evm_denom field

This change aligns with the PR objective to define EvmDenom as a constant, which helps prevent potential governance attacks by removing the ability to alter the denomination dynamically.

To ensure this change is fully implemented, please run the following script to verify that EvmDenom is defined as a constant elsewhere in the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for EvmDenom constant definition
rg --type go 'const\s+EvmDenom\s*='

Length of output: 1420

// DEPRECATED: enable_create
reserved 2;
// DEPRECATED: enable_call
Expand All @@ -44,9 +43,9 @@
];
// DEPRECATED: chain_config
reserved 5;
// allow_unprotected_txs defines if replay-protected (i.e non EIP155
// signed) transactions can be executed on the state machine.
bool allow_unprotected_txs = 6;
// DEPRECATED: allow_unprotected_txs
reserved 6;

// DEPRECATED: active_precompiles
// All precompiles present according to the VM are active.
reserved 7;
Expand Down
Loading
Loading