Skip to content

Commit

Permalink
feat(evm): add simple validation for fun token fee in set params (#2091)
Browse files Browse the repository at this point in the history
* feat: add simple validation for fun token fee in set params

* chore: changelog

* linting changelog

* lint: fix lint issues

---------

Co-authored-by: Unique-Divine <[email protected]>
  • Loading branch information
matthiasmatt and Unique-Divine authored Oct 24, 2024
1 parent 056edb3 commit 9ce1d87
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 11 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ consistent setup and dynamic gas calculations, addressing the following tickets.
- https://github.com/code-423n4/2024-10-nibiru-zenith/issues/47
- [#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

#### Nibiru EVM | Before Audit 1 - 2024-10-18

Expand Down Expand Up @@ -127,7 +128,7 @@ consistent setup and dynamic gas calculations, addressing the following tickets.
- [#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 @@ -143,7 +144,7 @@ consistent setup and dynamic gas calculations, addressing the following tickets.
- [#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
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
5 changes: 4 additions & 1 deletion x/evm/evmmodule/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ func InitGenesis(
accountKeeper evm.AccountKeeper,
genState evm.GenesisState,
) []abci.ValidatorUpdate {
k.SetParams(ctx, genState.Params)
err := k.SetParams(ctx, genState.Params)
if err != nil {
panic(fmt.Errorf("failed to set params: %w", err))
}

// Note that "GetModuleAccount" initializes the module account with permissions
// under the hood if it did not already exist. This is important because the
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 @@ func (k Keeper) GetParams(ctx sdk.Context) (params evm.Params) {
}

// 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)
}

k.EvmState.ModuleParams.Set(ctx, params)
return
}

// SetState updates contract storage and deletes if the value is empty.
Expand Down
7 changes: 5 additions & 2 deletions x/evm/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ func (s *Suite) TestQueryCode() {
func (s *Suite) TestQueryParams() {
deps := evmtest.NewTestDeps()
want := evm.DefaultParams()
deps.EvmKeeper.SetParams(deps.Ctx, want)
err := deps.EvmKeeper.SetParams(deps.Ctx, want)
s.NoError(err)

gotResp, err := deps.EvmKeeper.Params(sdk.WrapSDKContext(deps.Ctx), nil)
s.NoError(err)
got := gotResp.Params
Expand All @@ -458,7 +460,8 @@ func (s *Suite) TestQueryParams() {

// Empty params to test the setter
want.EVMChannels = []string{"channel-420"}
deps.EvmKeeper.SetParams(deps.Ctx, want)
err = deps.EvmKeeper.SetParams(deps.Ctx, want)
s.NoError(err)
gotResp, err = deps.EvmKeeper.Params(sdk.WrapSDKContext(deps.Ctx), nil)
s.Require().NoError(err)
got = gotResp.Params
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 @@ func (k *Keeper) UpdateParams(
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")
}
return &evm.MsgUpdateParamsResponse{}, nil
}

0 comments on commit 9ce1d87

Please sign in to comment.