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

feat(evm): add simple validation for fun token fee in set params #2091

Merged
merged 5 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#2002](https://github.com/NibiruChain/nibiru/pull/2002) - feat(evm): Add the account query to the EVM command. Cover the CLI with tests.
- [#2003](https://github.com/NibiruChain/nibiru/pull/2003) - fix(evm): fix FunToken conversions between Cosmos and EVM
- [#2004](https://github.com/NibiruChain/nibiru/pull/2004) - refactor(evm)!: replace `HexAddr` with `EIP55Addr`
- [#2006](https://github.com/NibiruChain/nibiru/pull/2006) - test(evm): e2e tests for eth_* endpoints
- [#2006](https://github.com/NibiruChain/nibiru/pull/2006) - test(evm): e2e tests for eth\_\* endpoints
- [#2008](https://github.com/NibiruChain/nibiru/pull/2008) - refactor(evm): clean up precompile setups
- [#2013](https://github.com/NibiruChain/nibiru/pull/2013) - chore(evm): Set appropriate gas value for the required gas of the "IFunToken.sol" precompile.
- [#2014](https://github.com/NibiruChain/nibiru/pull/2014) - feat(evm): Emit block bloom event in EndBlock hook.
Expand All @@ -124,19 +124,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#2044](https://github.com/NibiruChain/nibiru/pull/2044) - feat(evm): evm tx indexer service implemented
- [#2045](https://github.com/NibiruChain/nibiru/pull/2045) - test(evm): backend tests with test network and real txs
- [#2053](https://github.com/NibiruChain/nibiru/pull/2053) - refactor(evm): converted untyped event to typed and cleaned up
- [#2054](https://github.com/NibiruChain/nibiru/pull/2054) - feat(evm-precompile): Precompile for one-way EVM calls to invoke/execute Wasm contracts.
- [#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
- [#2073](https://github.com/NibiruChain/nibiru/pull/2073) - fix(evm-keeper): better utilize ERC20 metadata during FunToken creation
- [#2076](https://github.com/NibiruChain/nibiru/pull/2076) - fix(evm-gas-fees):
Use effective gas price in RefundGas and make sure that units are properly
reflected on all occurences of "base fee" in the codebase. This fixes [#2059](https://github.com/NibiruChain/nibiru/issues/2059)
and the [related comments from @Unique-Divine and @berndartmueller](https://github.com/NibiruChain/nibiru/issues/2059#issuecomment-2408625724).
Use effective gas price in RefundGas and make sure that units are properly
reflected on all occurences of "base fee" in the codebase. This fixes [#2059](https://github.com/NibiruChain/nibiru/issues/2059)
and the [related comments from @Unique-Divine and @berndartmueller](https://github.com/NibiruChain/nibiru/issues/2059#issuecomment-2408625724).
- [#2084](https://github.com/NibiruChain/nibiru/pull/2084) - feat(evm-forge): foundry support and template for Nibiru EVM develoment
- [#2088](https://github.com/NibiruChain/nibiru/pull/2088) - refactor(evm): remove outdated comment and improper error message text
- [#2089](https://github.com/NibiruChain/nibiru/pull/2089) - better handling of gas consumption within erc20 contract execution

- [#2091](https://github.com/NibiruChain/nibiru/pull/2091) - feat(evm): add fun token creation fee validation

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

Expand Down
24 changes: 20 additions & 4 deletions app/evmante/evmante_validate_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ func (s *TestSuite) TestEthValidateBasicDecorator() {
},
wantErr: "",
},
{
name: "sad: fail to set params",
txSetup: func(deps *evmtest.TestDeps) sdk.Tx {
return evmtest.HappyCreateContractTx(deps)
},
paramsSetup: func(deps *evmtest.TestDeps) evm.Params {
return evm.Params{
CreateFuntokenFee: sdk.NewInt(-1),
}
},
wantErr: "createFuntokenFee cannot be negative: -1",
},
{
name: "happy: ctx recheck should ignore validation",
ctxSetup: func(deps *evmtest.TestDeps) {
Expand Down Expand Up @@ -195,12 +207,16 @@ func (s *TestSuite) TestEthValidateBasicDecorator() {
if tc.ctxSetup != nil {
tc.ctxSetup(&deps)
}
var err error
if tc.paramsSetup != nil {
deps.EvmKeeper.SetParams(deps.Ctx, tc.paramsSetup(&deps))
err = deps.EvmKeeper.SetParams(deps.Ctx, tc.paramsSetup(&deps))
}

if err == nil {
_, err = anteDec.AnteHandle(
deps.Ctx, tx, false, evmtest.NextNoOpAnteHandler,
)
}
_, err := anteDec.AnteHandle(
deps.Ctx, tx, false, evmtest.NextNoOpAnteHandler,
)
if tc.wantErr != "" {
s.Require().ErrorContains(err, tc.wantErr)
return
Expand Down
8 changes: 7 additions & 1 deletion x/evm/keeper/evm_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package keeper

import (
"fmt"
"math/big"

"github.com/NibiruChain/collections"
Expand Down Expand Up @@ -116,8 +117,13 @@
}

// SetParams: Setter for the module parameters.
func (k Keeper) SetParams(ctx sdk.Context, params evm.Params) {
func (k Keeper) SetParams(ctx sdk.Context, params evm.Params) (err error) {
if params.CreateFuntokenFee.IsNegative() {
return fmt.Errorf("createFuntokenFee cannot be negative: %s", params.CreateFuntokenFee)
}

Check warning on line 123 in x/evm/keeper/evm_state.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/evm_state.go#L122-L123

Added lines #L122 - L123 were not covered by tests

k.EvmState.ModuleParams.Set(ctx, params)
return
Unique-Divine marked this conversation as resolved.
Show resolved Hide resolved
}

// SetState updates contract storage and deletes if the value is empty.
Expand Down
5 changes: 4 additions & 1 deletion x/evm/keeper/msg_update_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority, expected %s, got %s", k.authority.String(), req.Authority)
}
ctx := sdk.UnwrapSDKContext(goCtx)
k.SetParams(ctx, req.Params)
err = k.SetParams(ctx, req.Params)
if err != nil {
return nil, errors.Wrapf(err, "failed to set params")
}

Check warning on line 24 in x/evm/keeper/msg_update_params.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/msg_update_params.go#L21-L24

Added lines #L21 - L24 were not covered by tests
return &evm.MsgUpdateParamsResponse{}, nil
}
Loading