Skip to content

Commit

Permalink
Merge branch 'main' into releases/v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yang committed Nov 5, 2024
2 parents bd90938 + 94db838 commit 45bcbd0
Show file tree
Hide file tree
Showing 157 changed files with 12,627 additions and 6,029 deletions.
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.45.0
# - uses: bufbuild/buf-setup-action@v1.46.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.45.0
- uses: bufbuild/buf-setup-action@v1.46.0
with:
github_token: ${{ github.token }}
- uses: bufbuild/buf-breaking-action@v1
Expand Down
47 changes: 39 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ Zenith](https://code4rena.com/zenith) Audit, running from 2024-10-07 until
period. This section describes code changes that occured after that audit in
preparation for a second audit starting in November 2024.

- [#2074](https://github.com/NibiruChain/nibiru/pull/2074) - fix(evm-keeper): better utilize ERC20 metadata during FunToken creation. The bank metadata for a new FunToken mapping ties a connection between the Bank Coin's `DenomUnit` and the ERC20 contract metadata like the name, decimals, and symbol. This change brings parity between EVM wallets, such as MetaMask, and Interchain wallets like Keplr and Leap.
- [#2068](https://github.com/NibiruChain/nibiru/pull/2068) - feat: enable wasm light clients on IBC (08-wasm)
- [#2074](https://github.com/NibiruChain/nibiru/pull/2074) - fix(evm-keeper): better utilize ERC20 metadata during FunToken creation. The bank metadata for a new FunToken mapping ties a connection between the Bank Coin's `DenomUnit` and the ERC20 contract metadata like the name, decimals, and symbol. This change brings parity between EVM wallets, such as MetaMask, and Interchain wallets like Keplr and Leap.
- [#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
- [#2086](https://github.com/NibiruChain/nibiru/pull/2086) - fix(evm-precomples):
Fix state consistency in precompile execution by ensuring proper journaling of
Expand All @@ -63,12 +64,42 @@ committed as expected, fixes the `StateDB.Commit` to follow its guidelines more
closely, and solves for a critical state inconsistency producible from the
FunToken.sol precompiled contract. It also aligns the precompiles to use
consistent setup and dynamic gas calculations, addressing the following tickets.
- https://github.com/NibiruChain/nibiru/issues/2083
- https://github.com/code-423n4/2024-10-nibiru-zenith/issues/43
- https://github.com/code-423n4/2024-10-nibiru-zenith/issues/47
- <https://github.com/NibiruChain/nibiru/issues/2083>
- <https://github.com/code-423n4/2024-10-nibiru-zenith/issues/43>
- <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
- [#2090](https://github.com/NibiruChain/nibiru/pull/2090) - fix(evm): Account
for (1) ERC20 transfers with tokens that return false success values instead of
throwing an error and (2) ERC20 transfers with other operations that don't bring
about the expected resulting balance for the transfer recipient.
- [#2091](https://github.com/NibiruChain/nibiru/pull/2091) - feat(evm): add fun token creation fee validation
- [#2093](https://github.com/NibiruChain/nibiru/pull/2093) - feat(evm): gas usage in precompiles: limits, local gas meters
- [#2092](https://github.com/NibiruChain/nibiru/pull/2092) - feat(evm): add validation for wasm multi message execution
- [#2094](https://github.com/NibiruChain/nibiru/pull/2094) - fix(evm): Following
from the changs in #2086, this pull request implements a new `JournalChange`
struct that saves a deep copy of the state multi store before each
state-modifying, Nibiru-specific precompiled contract is called (`OnRunStart`).
Additionally, we commit the `StateDB` there as well. This guarantees that the
non-EVM and EVM state will be in sync even if there are complex, multi-step
Ethereum transactions, such as in the case of an EthereumTx that influences the
`StateDB`, then calls a precompile that also changes non-EVM state, and then EVM
reverts inside of a try-catch.
- [#2095](https://github.com/NibiruChain/nibiru/pull/2095) - fix(evm): This
change records NIBI (ether) transfers on the `StateDB` during precompiled
contract calls using the `NibiruBankKeeper`, which is struct extension of
the `bankkeeper.BaseKeeper` that is used throughout Nibiru.
The `NibiruBankKeeper` holds a reference to the current EVM `StateDB` and records
balance changes in wei as journal changes automatically. This guarantees that
commits and reversions of the `StateDB` do not misalign with the state of the
Bank module. This code change uses the `NibiruBankKeeper` on all modules that
depend on x/bank, such as the EVM and Wasm modules.
- [#2097](https://github.com/NibiruChain/nibiru/pull/2097) - feat(evm): Add new query to get dated price from the oracle precompile
- [#2098](https://github.com/NibiruChain/nibiru/pull/2098) - test(evm): statedb
tests for race conditions within funtoken precompile
- [#2100](https://github.com/NibiruChain/nibiru/pull/2100) - refactor: cleanup statedb and precompile sections
- [#2101](https://github.com/NibiruChain/nibiru/pull/2101) - fix(evm): tx receipt proper marshalling
- [#2105](https://github.com/NibiruChain/nibiru/pull/2105) - test(evm): precompile call with revert

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

Expand Down Expand Up @@ -210,7 +241,7 @@ consistent setup and dynamic gas calculations, addressing the following tickets.
- 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.2 ([#1862](https://github.com/NibiruChain/nibiru/pull/1862), [#2070](https://github.com/NibiruChain/nibiru/pull/2070))
- 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.45.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), [#2062](https://github.com/NibiruChain/nibiru/pull/2062), [#2069](https://github.com/NibiruChain/nibiru/pull/2069))
- Bump `bufbuild/buf-setup-action` from 1.30.1 to 1.46.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), [#2062](https://github.com/NibiruChain/nibiru/pull/2062), [#2069](https://github.com/NibiruChain/nibiru/pull/2069), [#2102](https://github.com/NibiruChain/nibiru/pull/2102))
- Bump `axios` from 1.7.3 to 1.7.4 ([#2016](https://github.com/NibiruChain/nibiru/pull/2016))
- Bump `github.com/CosmWasm/wasmvm` from 1.5.0 to 1.5.5 ([#2047](https://github.com/NibiruChain/nibiru/pull/2047))
- Bump `docker/build-push-action` from 5 to 6 ([#1924](https://github.com/NibiruChain/nibiru/pull/1924))
Expand Down
2 changes: 1 addition & 1 deletion app/ante/gas_wanted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *AnteTestSuite) TestGasWantedDecorator() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
stateDB := deps.NewStateDB()
anteDec := ante.AnteDecoratorGasWanted{}

tx := tc.txSetup(&deps)
Expand Down
2 changes: 1 addition & 1 deletion app/ante/handler_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type AnteHandlerOptions struct {
IBCKeeper *ibckeeper.Keeper
DevGasKeeper *devgaskeeper.Keeper
DevGasBankKeeper devgasante.BankKeeper
EvmKeeper evmkeeper.Keeper
EvmKeeper *evmkeeper.Keeper
AccountKeeper authkeeper.AccountKeeper

TxCounterStoreKey types.StoreKey
Expand Down
14 changes: 14 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
cmtos "github.com/cometbft/cometbft/libs/os"
tmos "github.com/cometbft/cometbft/libs/os"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
Expand All @@ -37,6 +39,7 @@ import (
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
"github.com/cosmos/cosmos-sdk/x/crisis"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
ibcwasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
"github.com/cosmos/ibc-go/v7/testing/types"
Expand Down Expand Up @@ -235,6 +238,10 @@ func NewNibiruApp(
app.CommitMultiStore(),
&app.WasmKeeper,
),
ibcwasmkeeper.NewWasmSnapshotter(
app.CommitMultiStore(),
&app.WasmClientKeeper,
),
); err != nil {
panic("failed to add wasm snapshot extension.")
}
Expand All @@ -245,6 +252,13 @@ func NewNibiruApp(
tmos.Exit(err.Error())
}

ctx := app.BaseApp.NewUncachedContext(true, cmtproto.Header{})

// Initialize pinned codes in wasmvm as they are not persisted there
if err := ibcwasmkeeper.InitializePinnedCodes(ctx, app.appCodec); err != nil {
cmtos.Exit(fmt.Sprintf("failed to initialize pinned codes %s", err))
}

/* Applications that wish to enforce statically created ScopedKeepers should
call `Seal` after creating their scoped modules in `NewApp` with
`capabilityKeeper.ScopeToModule`.
Expand Down
3 changes: 1 addition & 2 deletions app/evmante/evmante_can_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ func (ctd CanTransferDecorator) AnteHandle(
BaseFeeWei: baseFeeWeiPerGas,
}

stateDB := statedb.New(
stateDB := ctd.NewStateDB(
ctx,
ctd.EVMKeeper,
statedb.NewEmptyTxConfig(gethcommon.BytesToHash(ctx.HeaderHash().Bytes())),
)
evmInstance := ctd.EVMKeeper.NewEVM(ctx, coreMsg, cfg, evm.NewNoOpTracer(), stateDB)
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_can_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func (s *TestSuite) TestCanTransferDecorator() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.CanTransferDecorator{&deps.App.AppKeepers.EvmKeeper}
stateDB := deps.NewStateDB()
anteDec := evmante.CanTransferDecorator{deps.App.AppKeepers.EvmKeeper}
tx := tc.txSetup(&deps)

if tc.ctxSetup != nil {
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_emit_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func (s *TestSuite) TestEthEmitEventDecorator() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewEthEmitEventDecorator(&deps.App.AppKeepers.EvmKeeper)
stateDB := deps.NewStateDB()
anteDec := evmante.NewEthEmitEventDecorator(deps.App.AppKeepers.EvmKeeper)

tx := tc.txSetup(&deps)
s.Require().NoError(stateDB.Commit())
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_gas_consume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func (s *TestSuite) TestAnteDecEthGasConsume() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
stateDB := deps.NewStateDB()
anteDec := evmante.NewAnteDecEthGasConsume(
&deps.App.AppKeepers.EvmKeeper, tc.maxGasWanted,
deps.App.AppKeepers.EvmKeeper, tc.maxGasWanted,
)

tc.beforeTxSetup(&deps, stateDB)
Expand Down
18 changes: 9 additions & 9 deletions app/evmante/evmante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ func NewAnteHandlerEVM(
) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
// outermost AnteDecorator. SetUpContext must be called first
NewEthSetUpContextDecorator(&options.EvmKeeper),
NewMempoolGasPriceDecorator(&options.EvmKeeper),
NewEthValidateBasicDecorator(&options.EvmKeeper),
NewEthSigVerificationDecorator(&options.EvmKeeper),
NewAnteDecVerifyEthAcc(&options.EvmKeeper, options.AccountKeeper),
CanTransferDecorator{&options.EvmKeeper},
NewAnteDecEthGasConsume(&options.EvmKeeper, options.MaxTxGasWanted),
NewAnteDecEthIncrementSenderSequence(&options.EvmKeeper, options.AccountKeeper),
NewEthSetUpContextDecorator(options.EvmKeeper),
NewMempoolGasPriceDecorator(options.EvmKeeper),
NewEthValidateBasicDecorator(options.EvmKeeper),
NewEthSigVerificationDecorator(options.EvmKeeper),
NewAnteDecVerifyEthAcc(options.EvmKeeper, options.AccountKeeper),
CanTransferDecorator{options.EvmKeeper},
NewAnteDecEthGasConsume(options.EvmKeeper, options.MaxTxGasWanted),
NewAnteDecEthIncrementSenderSequence(options.EvmKeeper, options.AccountKeeper),
ante.AnteDecoratorGasWanted{},
// emit eth tx hash and index at the very last ante handler.
NewEthEmitEventDecorator(&options.EvmKeeper),
NewEthEmitEventDecorator(options.EvmKeeper),
)
}
2 changes: 1 addition & 1 deletion app/evmante/evmante_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s *TestSuite) TestAnteHandlerEVM() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
stateDB := deps.NewStateDB()

anteHandlerEVM := evmante.NewAnteHandlerEVM(
ante.AnteHandlerOptions{
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_increment_sender_seq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (s *TestSuite) TestAnteDecEthIncrementSenderSequence() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewAnteDecEthIncrementSenderSequence(&deps.App.EvmKeeper, deps.App.AccountKeeper)
stateDB := deps.NewStateDB()
anteDec := evmante.NewAnteDecEthIncrementSenderSequence(deps.App.EvmKeeper, deps.App.AccountKeeper)

if tc.beforeTxSetup != nil {
tc.beforeTxSetup(&deps, stateDB)
Expand Down
2 changes: 1 addition & 1 deletion app/evmante/evmante_mempool_fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *TestSuite) TestMempoolGasFeeDecorator() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
anteDec := evmante.NewMempoolGasPriceDecorator(&deps.App.AppKeepers.EvmKeeper)
anteDec := evmante.NewMempoolGasPriceDecorator(deps.App.AppKeepers.EvmKeeper)

tx := tc.txSetup(&deps)

Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_setup_ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

func (s *TestSuite) TestEthSetupContextDecorator() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewEthSetUpContextDecorator(&deps.App.EvmKeeper)
stateDB := deps.NewStateDB()
anteDec := evmante.NewEthSetUpContextDecorator(deps.App.EvmKeeper)

s.Require().NoError(stateDB.Commit())
tx := evmtest.HappyCreateContractTx(&deps)
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_sigverify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (s *TestSuite) TestEthSigVerificationDecorator() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewEthSigVerificationDecorator(&deps.App.AppKeepers.EvmKeeper)
stateDB := deps.NewStateDB()
anteDec := evmante.NewEthSigVerificationDecorator(deps.App.AppKeepers.EvmKeeper)

tx := tc.txSetup(&deps)
s.Require().NoError(stateDB.Commit())
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_validate_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ func (s *TestSuite) TestEthValidateBasicDecorator() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewEthValidateBasicDecorator(&deps.App.AppKeepers.EvmKeeper)
stateDB := deps.NewStateDB()
anteDec := evmante.NewEthValidateBasicDecorator(deps.App.AppKeepers.EvmKeeper)

tx := tc.txSetup(&deps)
s.Require().NoError(stateDB.Commit())
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_verify_eth_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func (s *TestSuite) TestAnteDecoratorVerifyEthAcc_CheckTx() {
for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
stateDB := deps.StateDB()
anteDec := evmante.NewAnteDecVerifyEthAcc(&deps.App.AppKeepers.EvmKeeper, &deps.App.AppKeepers.AccountKeeper)
stateDB := deps.NewStateDB()
anteDec := evmante.NewAnteDecVerifyEthAcc(deps.App.AppKeepers.EvmKeeper, &deps.App.AppKeepers.AccountKeeper)

tc.beforeTxSetup(&deps, stateDB)
tx := tc.txSetup(&deps)
Expand Down
Loading

0 comments on commit 45bcbd0

Please sign in to comment.