Skip to content

Commit

Permalink
Merge branch 'main' into on/refactor_evm_events
Browse files Browse the repository at this point in the history
  • Loading branch information
Unique-Divine authored Oct 2, 2024
2 parents 5957c08 + fa62d35 commit 7acd795
Show file tree
Hide file tree
Showing 35 changed files with 1,912 additions and 136 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/gh-issues.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: "Auto-add GH issues to project"
# Add all issues opened to the issue board for triage and assignment
# GitHub Org and Project Automation
# https://www.notion.so/nibiru/GitHub-Org-and-Project-Automation-c771d671109849ee9fda7c8b741cd66a?pvs=4

on:
issues:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/proto-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
# timeout-minutes: 5
# steps:
# - uses: actions/checkout@v4
# - uses: bufbuild/buf-setup-action@v1.36.0
# - uses: bufbuild/buf-setup-action@v1.43.0
# - uses: bufbuild/buf-lint-action@v1
# with:
# input: "proto"
Expand All @@ -31,7 +31,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-setup-action@v1.36.0
- uses: bufbuild/buf-setup-action@v1.43.0
with:
github_token: ${{ github.token }}
- uses: bufbuild/buf-breaking-action@v1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ temp*
txout.json
vote.json
**__pycache**
scratch-paper.md

### TypeScript and Friends

Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#2023](https://github.com/NibiruChain/nibiru/pull/2023) - fix(evm)!: adjusted generation and parsing of the block bloom events
- [#2030](https://github.com/NibiruChain/nibiru/pull/2030) - refactor(eth/rpc): Delete unused code and improve logging in the eth and debug namespaces
- [#2031](https://github.com/NibiruChain/nibiru/pull/2031) - fix(evm): debug calls with custom tracer and tracer options
- [#2032](https://github.com/NibiruChain/nibiru/pull/2032) - feat(evm): ante handler to prohibit authz grant evm messages
- [#2039](https://github.com/NibiruChain/nibiru/pull/2039) - refactor(rpc-backend): remove unnecessary interface code
- [#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.

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

Expand Down Expand Up @@ -152,6 +154,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1913](https://github.com/NibiruChain/nibiru/pull/1913) - fix(tests): race condition from heavy Network tests
- [#1992](https://github.com/NibiruChain/nibiru/pull/1992) - chore: enabled grpc for localnet
- [#1999](https://github.com/NibiruChain/nibiru/pull/1999) - chore: update nibi go package version to v2
- [#2050](https://github.com/NibiruChain/nibiru/pull/2050) - refactor(oracle): remove unused code and collapse empty client/cli directory

### Dependencies

Expand All @@ -174,7 +177,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bump `github.com/hashicorp/go-getter` from 1.7.1 to 1.7.5 ([#1858](https://github.com/NibiruChain/nibiru/pull/1858), [#1938](https://github.com/NibiruChain/nibiru/pull/1938))
- Bump `github.com/btcsuite/btcd` from 0.23.3 to 0.24.0 ([#1862](https://github.com/NibiruChain/nibiru/pull/1862))
- Bump `pozetroninc/github-action-get-latest-release` from 0.7.0 to 0.8.0 ([#1863](https://github.com/NibiruChain/nibiru/pull/1863))
- Bump `bufbuild/buf-setup-action` from 1.30.1 to 1.36.0 ([#1891](https://github.com/NibiruChain/nibiru/pull/1891), [#1900](https://github.com/NibiruChain/nibiru/pull/1900), [#1923](https://github.com/NibiruChain/nibiru/pull/1923), [#1972](https://github.com/NibiruChain/nibiru/pull/1972), [#1974](https://github.com/NibiruChain/nibiru/pull/1974), [#1988](https://github.com/NibiruChain/nibiru/pull/1988))
- Bump `bufbuild/buf-setup-action` from 1.30.1 to 1.43.0 ([#1891](https://github.com/NibiruChain/nibiru/pull/1891), [#1900](https://github.com/NibiruChain/nibiru/pull/1900), [#1923](https://github.com/NibiruChain/nibiru/pull/1923), [#1972](https://github.com/NibiruChain/nibiru/pull/1972), [#1974](https://github.com/NibiruChain/nibiru/pull/1974), [#1988](https://github.com/NibiruChain/nibiru/pull/1988), [#2043](https://github.com/NibiruChain/nibiru/pull/2043), [#2057](https://github.com/NibiruChain/nibiru/pull/2057))
- Bump `axios` from 1.7.3 to 1.7.4 ([#2016](https://github.com/NibiruChain/nibiru/pull/2016))

## [v1.5.0](https://github.com/NibiruChain/nibiru/releases/tag/v1.5.0) - 2024-06-21
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ If you have questions or concerns, feel free to connect with a developer or comm

| Module | Description |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Wasm][code-x-wasm] | Implements the execution environment for WebAssembly (WASM) smart contracts. CosmWasm smart contracts are Rust-based, Wasm smart contracts built for enhanced security, performance, and interoperability. See our [CosmWasm sandbox monorepo (cw-nibiru)](https://github.com/NibiruChain/cw-nibiru/tree/main) for the protocol's core smart contracts. |
| [Wasm][code-x-wasm] | Implements the execution environment for WebAssembly (WASM) smart contracts. CosmWasm smart contracts are Rust-based, Wasm smart contracts built for enhanced security, performance, and interoperability. See our [CosmWasm sandbox monorepo (nibiru-wasm)](https://github.com/NibiruChain/nibiru-wasm/tree/main) for the protocol's core smart contracts. |
| [EVM][code-x-evm] | Implements Nibiru EVM, which manages an Ethereum Virtual Machine (EVM) state database and enables the execution of Ethereum smart contracts. Nibiru EVM is an extension of "[geth](https://github.com/ethereum/go-ethereum)" along with "web3" and "eth" JSON-RPC methods. |
| [Devgas][code-x-devgas] | The `devgas` module of Nibiru Chain shares contract execution fees with smart contract developers. This aims to increase the adoption of Nibiru by offering CosmWasm smart contract developers a direct source of income based on usage. |
| [Epochs][code-x-epochs] | The `epochs` module allows other modules to set hooks to be called to execute code automatically on a period basis. For example, "once a week, starting at UTC-time = x". `epochs` creates a generalized epoch interface. |
Expand Down
1 change: 1 addition & 0 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func NewAnteHandlerNonEVM(
) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ante.AnteDecoratorPreventEtheruemTxMsgs{}, // reject MsgEthereumTxs
ante.AnteDecoratorAuthzGuard{}, // disable certain messages in authz grant "generic"
authante.NewSetUpContextDecorator(),
wasmkeeper.NewLimitSimulationGasDecorator(opts.WasmConfig.SimulationGasLimit),
wasmkeeper.NewCountTXDecorator(opts.TxCounterStoreKey),
Expand Down
138 changes: 138 additions & 0 deletions app/ante/auth_grard_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package ante_test

import (
"time"

sdkclienttx "github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/NibiruChain/nibiru/v2/app"
"github.com/NibiruChain/nibiru/v2/app/ante"
"github.com/NibiruChain/nibiru/v2/x/evm"
"github.com/NibiruChain/nibiru/v2/x/evm/evmtest"
)

func (s *AnteTestSuite) TestAnteDecoratorAuthzGuard() {
testCases := []struct {
name string
txMsg func() sdk.Msg
wantErr string
}{
{
name: "sad: authz generic grant with evm message",
txMsg: func() sdk.Msg {
someTime := time.Now()
expiryTime := someTime.Add(time.Hour)
genericGrant, err := authz.NewGrant(
someTime,
authz.NewGenericAuthorization(sdk.MsgTypeURL(&evm.MsgEthereumTx{})), &expiryTime,
)
s.Require().NoError(err)
return &authz.MsgGrant{Grant: genericGrant}
},
wantErr: "not allowed",
},
{
name: "happy: authz generic grant with non evm message",
txMsg: func() sdk.Msg {
someTime := time.Now()
expiryTime := someTime.Add(time.Hour)
genericGrant, err := authz.NewGrant(
someTime,
authz.NewGenericAuthorization(sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{})), &expiryTime,
)
s.Require().NoError(err)
return &authz.MsgGrant{Grant: genericGrant}
},
wantErr: "",
},
{
name: "happy: authz non generic grant",
txMsg: func() sdk.Msg {
someTime := time.Now()
expiryTime := someTime.Add(time.Hour)
genericGrant, err := authz.NewGrant(
someTime,
&banktypes.SendAuthorization{},
&expiryTime,
)
s.Require().NoError(err)
return &authz.MsgGrant{Grant: genericGrant}
},
wantErr: "",
},
{
name: "happy: non authz message",
txMsg: func() sdk.Msg {
return &evm.MsgEthereumTx{}
},
wantErr: "",
},
{
name: "sad: authz exec with a single evm message",
txMsg: func() sdk.Msg {
msgExec := authz.NewMsgExec(
sdk.AccAddress("nibiuser"),
[]sdk.Msg{
&evm.MsgEthereumTx{},
},
)
return &msgExec
},
wantErr: "ExtensionOptionsEthereumTx",
},
{
name: "sad: authz exec with evm message and non evm message",
txMsg: func() sdk.Msg {
msgExec := authz.NewMsgExec(
sdk.AccAddress("nibiuser"),
[]sdk.Msg{
&banktypes.MsgSend{},
&evm.MsgEthereumTx{},
},
)
return &msgExec
},
wantErr: "ExtensionOptionsEthereumTx",
},
{
name: "happy: authz exec without evm messages",
txMsg: func() sdk.Msg {
msgExec := authz.NewMsgExec(
sdk.AccAddress("nibiuser"),
[]sdk.Msg{
&banktypes.MsgSend{},
},
)
return &msgExec
},
wantErr: "",
},
}

for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
anteDec := ante.AnteDecoratorAuthzGuard{}

encCfg := app.MakeEncodingConfig()
txBuilder, err := sdkclienttx.Factory{}.
WithChainID(s.ctx.ChainID()).
WithTxConfig(encCfg.TxConfig).
BuildUnsignedTx(tc.txMsg())
s.Require().NoError(err)

_, err = anteDec.AnteHandle(
deps.Ctx, txBuilder.GetTx(), false, evmtest.NextNoOpAnteHandler,
)
if tc.wantErr != "" {
s.Require().ErrorContains(err, tc.wantErr)
return
}
s.Require().NoError(err)
})
}
}
72 changes: 65 additions & 7 deletions app/ante/authz_guard.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,67 @@
// Copyright (c) 2023-2024 Nibi, Inc.
package ante

// TODO: https://github.com/NibiruChain/nibiru/issues/1915
// feat(ante): Add an authz guard to disable authz Ethereum txs and provide
// additional security around the default functionality exposed by the module.
//
// Implemenetation Notes
// UD-NOTE - IsAuthzMessage fn. Use authz import with module name
// UD-NOTE - Define set of disabled txMsgs
import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/authz"

"github.com/NibiruChain/nibiru/v2/x/evm"
)

// AnteDecoratorAuthzGuard filters autz messages
type AnteDecoratorAuthzGuard struct{}

// AnteHandle rejects "authz grant generic --msg-type '/eth.evm.v1.MsgEthereumTx'"
// Also rejects authz exec tx.json with any MsgEthereumTx inside
func (rmd AnteDecoratorAuthzGuard) AnteHandle(
ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler,
) (newCtx sdk.Context, err error) {
for _, msg := range tx.GetMsgs() {
// Do not allow grant for MsgEthereumTx
if msgGrant, ok := msg.(*authz.MsgGrant); ok {
if msgGrant.Grant.Authorization == nil {
return ctx, errors.Wrapf(
errortypes.ErrInvalidType,
"grant authorization is missing",
)
}
authorization, err := msgGrant.Grant.GetAuthorization()
if err != nil {
return ctx, errors.Wrapf(
errortypes.ErrInvalidType,
"failed unmarshaling generic authorization %s", err,
)
}
if genericAuth, ok := authorization.(*authz.GenericAuthorization); ok {
if genericAuth.MsgTypeURL() == sdk.MsgTypeURL(&evm.MsgEthereumTx{}) {
return ctx, errors.Wrapf(
errortypes.ErrNotSupported,
"authz grant generic for msg type %s is not allowed",
genericAuth.MsgTypeURL(),
)
}
}
}
// Also reject MsgEthereumTx in exec
if msgExec, ok := msg.(*authz.MsgExec); ok {
msgsInExec, err := msgExec.GetMessages()
if err != nil {
return ctx, errors.Wrapf(
errortypes.ErrInvalidType,
"failed getting exec messages %s", err,
)
}
for _, msgInExec := range msgsInExec {
if _, ok := msgInExec.(*evm.MsgEthereumTx); ok {
return ctx, errors.Wrapf(
errortypes.ErrInvalidType,
"MsgEthereumTx needs to be contained within a tx with 'ExtensionOptionsEthereumTx' option",
)
}
}
}
}
return next(ctx, tx, simulate)
}
2 changes: 1 addition & 1 deletion cmd/nibid/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/spf13/cobra"

"github.com/NibiruChain/nibiru/v2/app"
oraclecli "github.com/NibiruChain/nibiru/v2/x/oracle/client/cli"
oraclecli "github.com/NibiruChain/nibiru/v2/x/oracle/cli"
)

// NewRootCmd creates a new root command for nibid. It is called once in the
Expand Down
23 changes: 14 additions & 9 deletions eth/rpc/backend/backend_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package backend_test

import (
"context"
"crypto/ecdsa"
"fmt"
"math/big"
"testing"
"time"

"crypto/ecdsa"

sdk "github.com/cosmos/cosmos-sdk/types"
gethcommon "github.com/ethereum/go-ethereum/common"
gethcore "github.com/ethereum/go-ethereum/core/types"
Expand All @@ -33,15 +32,21 @@ import (
"github.com/NibiruChain/nibiru/v2/x/common/testutil/testnetwork"
)

var recipient = evmtest.NewEthPrivAcc().EthAddr
var amountToSend = evm.NativeToWei(big.NewInt(1))
var (
recipient = evmtest.NewEthPrivAcc().EthAddr
amountToSend = evm.NativeToWei(big.NewInt(1))
)

var transferTxBlockNumber rpc.BlockNumber
var transferTxBlockHash gethcommon.Hash
var transferTxHash gethcommon.Hash
var (
transferTxBlockNumber rpc.BlockNumber
transferTxBlockHash gethcommon.Hash
transferTxHash gethcommon.Hash
)

var testContractAddress gethcommon.Address
var deployContractBlockNumber rpc.BlockNumber
var (
testContractAddress gethcommon.Address
deployContractBlockNumber rpc.BlockNumber
)

type BackendSuite struct {
suite.Suite
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/gorilla/websocket v1.5.0
github.com/rs/cors v1.8.3
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4
golang.org/x/crypto v0.21.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/net v0.23.0
golang.org/x/text v0.14.0
Expand Down Expand Up @@ -201,7 +203,6 @@ require (
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
Expand All @@ -223,7 +224,6 @@ require (
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion x/common/testutil/testnetwork/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/spf13/cobra"

"github.com/NibiruChain/nibiru/v2/x/common/asset"
oraclecli "github.com/NibiruChain/nibiru/v2/x/oracle/client/cli"
oraclecli "github.com/NibiruChain/nibiru/v2/x/oracle/cli"
oracletypes "github.com/NibiruChain/nibiru/v2/x/oracle/types"
sudocli "github.com/NibiruChain/nibiru/v2/x/sudo/cli"
sudotypes "github.com/NibiruChain/nibiru/v2/x/sudo/types"
Expand Down
3 changes: 1 addition & 2 deletions x/common/testutil/testnetwork/start_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ func startNodeAndServers(cfg Config, val *Validator) error {
val.EthTxIndexer = evmTxIndexer
val.EthTxIndexerService = evmTxIndexerService

val.jsonrpc, val.jsonrpcDone, err =
server.StartJSONRPC(val.Ctx, val.ClientCtx, tmRPCAddr, tmEndpoint, val.AppConfig, val.EthTxIndexer)
val.jsonrpc, val.jsonrpcDone, err = server.StartJSONRPC(val.Ctx, val.ClientCtx, tmRPCAddr, tmEndpoint, val.AppConfig, val.EthTxIndexer)
if err != nil {
return errors.Wrap(err, "failed to start JSON-RPC server")
}
Expand Down
Loading

0 comments on commit 7acd795

Please sign in to comment.