Skip to content

Commit

Permalink
Merge branch 'main' into ud/fix-sims
Browse files Browse the repository at this point in the history
  • Loading branch information
Unique-Divine committed Jan 7, 2025
2 parents 0f84df4 + df8c394 commit 1eb06dd
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 22 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Remove unnecessary argument in the `VerifyFee` function, which returns the token
payment required based on the effective fee from the tx data. Improve
documentation.
- [#2127](https://github.com/NibiruChain/nibiru/pull/2127) - fix(vesting): disabled built in auth/vesting module functionality
- [#2125](https://github.com/NibiruChain/nibiru/pull/2125) - feat(evm-precompile):Emit EVM events created to reflect the ABCI events that occur outside the EVM to make sure that block explorers and indexers can find indexed ABCI event information.
- [#2127](https://github.com/NibiruChain/nibiru/pull/2127) - fix(vesting): disabled built in auth/vesting module functionality
- [#2129](https://github.com/NibiruChain/nibiru/pull/2129) - fix(evm): issue with infinite recursion in erc20 funtoken contracts
- [#2130](https://github.com/NibiruChain/nibiru/pull/2130) - fix(evm): proper nonce management in statedb
- [#2134](https://github.com/NibiruChain/nibiru/pull/2134) - fix(evm): query of NIBI should use bank state, not the StateDB
- [#2139](https://github.com/NibiruChain/nibiru/pull/2139) - fix(evm): erc20 born funtoken: properly burn bank coins after converting coin back to erc20
- [#2140](https://github.com/NibiruChain/nibiru/pull/2140) - fix(bank): bank keeper extension now charges gas for the bank operations
- [#2141](https://github.com/NibiruChain/nibiru/pull/2141) - refactor: simplify account retrieval operation in `nibid q evm account`.
- [#2142](https://github.com/NibiruChain/nibiru/pull/2142) - fix(bank): add additional missing methods to the NibiruBankKeeper
- [#2144](https://github.com/NibiruChain/nibiru/pull/2144) - feat(token-registry): Implement strongly typed Nibiru Token Registry and generation command
- [#2145](https://github.com/NibiruChain/nibiru/pull/2145) - chore(token-registry): add xNIBI Astrovault LST to registry
- [#2147](https://github.com/NibiruChain/nibiru/pull/2147) - fix(simapp): manually add x/vesting Cosmos-SDK module types to the codec in simulation tests since they are expected by default

#### Nibiru EVM | Before Audit 2 - 2024-12-06
Expand Down
82 changes: 76 additions & 6 deletions eth/rpc/backend/backend_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
gethcommon "github.com/ethereum/go-ethereum/common"
gethcore "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -115,13 +116,12 @@ func (s *BackendSuite) SendNibiViaEthTransfer(
amount *big.Int,
waitForNextBlock bool,
) gethcommon.Hash {
nonce, err := s.backend.GetTransactionCount(s.fundedAccEthAddr, rpc.EthPendingBlockNumber)
s.Require().NoError(err)
nonce := s.getCurrentNonce(s.fundedAccEthAddr)
return SendTransaction(
s,
&gethcore.LegacyTx{
To: &to,
Nonce: uint64(*nonce),
Nonce: uint64(nonce),
Value: amount,
Gas: params.TxGas,
GasPrice: big.NewInt(1),
Expand All @@ -135,20 +135,20 @@ func (s *BackendSuite) DeployTestContract(waitForNextBlock bool) (gethcommon.Has
packedArgs, err := embeds.SmartContract_TestERC20.ABI.Pack("")
s.Require().NoError(err)
bytecodeForCall := append(embeds.SmartContract_TestERC20.Bytecode, packedArgs...)
nonce, err := s.backend.GetTransactionCount(s.fundedAccEthAddr, rpc.EthPendingBlockNumber)
nonce := s.getCurrentNonce(s.fundedAccEthAddr)
s.Require().NoError(err)

txHash := SendTransaction(
s,
&gethcore.LegacyTx{
Nonce: uint64(*nonce),
Nonce: uint64(nonce),
Data: bytecodeForCall,
Gas: 1500_000,
GasPrice: big.NewInt(1),
},
waitForNextBlock,
)
contractAddr := crypto.CreateAddress(s.fundedAccEthAddr, (uint64)(*nonce))
contractAddr := crypto.CreateAddress(s.fundedAccEthAddr, nonce)
return txHash, contractAddr
}

Expand Down Expand Up @@ -188,3 +188,73 @@ func WaitForReceipt(s *BackendSuite, txHash gethcommon.Hash) (*big.Int, *gethcom
}
}
}

// getCurrentNonce returns the current nonce of the funded account
func (s *BackendSuite) getCurrentNonce(address gethcommon.Address) uint64 {
bn, err := s.backend.BlockNumber()
s.Require().NoError(err)
currentHeight := rpc.BlockNumber(bn)

nonce, err := s.backend.GetTransactionCount(address, currentHeight)
s.Require().NoError(err)

return uint64(*nonce)
}

// broadcastSDKTx broadcasts the given SDK transaction and returns the response
func (s *BackendSuite) broadcastSDKTx(sdkTx sdk.Tx) *sdk.TxResponse {
txBytes, err := s.backend.ClientCtx().TxConfig.TxEncoder()(sdkTx)
s.Require().NoError(err)

syncCtx := s.backend.ClientCtx().WithBroadcastMode(flags.BroadcastSync)
rsp, err := syncCtx.BroadcastTx(txBytes)
s.Require().NoError(err)
return rsp
}

// buildContractCreationTx builds a contract creation transaction
func (s *BackendSuite) buildContractCreationTx(nonce uint64) gethcore.Transaction {
packedArgs, err := embeds.SmartContract_TestERC20.ABI.Pack("")
s.Require().NoError(err)
bytecodeForCall := append(embeds.SmartContract_TestERC20.Bytecode, packedArgs...)

creationTx := &gethcore.LegacyTx{
Nonce: nonce,
Data: bytecodeForCall,
Gas: 1_500_000,
GasPrice: big.NewInt(1),
}

signer := gethcore.LatestSignerForChainID(s.ethChainID)
signedTx, err := gethcore.SignNewTx(s.fundedAccPrivateKey, signer, creationTx)
s.Require().NoError(err)

return *signedTx
}

// buildContractCallTx builds a contract call transaction
func (s *BackendSuite) buildContractCallTx(nonce uint64, contractAddr gethcommon.Address) gethcore.Transaction {
//recipient := crypto.CreateAddress(s.fundedAccEthAddr, 29381)
transferAmount := big.NewInt(100)

packedArgs, err := embeds.SmartContract_TestERC20.ABI.Pack(
"transfer",
recipient,
transferAmount,
)
s.Require().NoError(err)

transferTx := &gethcore.LegacyTx{
Nonce: nonce,
Data: packedArgs,
Gas: 100_000,
GasPrice: big.NewInt(1),
To: &contractAddr,
}

signer := gethcore.LatestSignerForChainID(s.ethChainID)
signedTx, err := gethcore.SignNewTx(s.fundedAccPrivateKey, signer, transferTx)
s.Require().NoError(err)

return *signedTx
}
5 changes: 5 additions & 0 deletions eth/rpc/backend/call_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math/big"

errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -338,3 +339,7 @@ func (b *Backend) GasPrice() (*hexutil.Big, error) {

return (*hexutil.Big)(result), nil
}

func (b *Backend) ClientCtx() client.Context {
return b.clientCtx
}
75 changes: 75 additions & 0 deletions eth/rpc/backend/nonce_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package backend_test

import (
sdkmath "cosmossdk.io/math"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
gethcore "github.com/ethereum/go-ethereum/core/types"

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

// TestNonceIncrementWithMultipleMsgsTx tests that the nonce is incremented correctly
// when multiple messages are included in a single transaction.
func (s *BackendSuite) TestNonceIncrementWithMultipleMsgsTx() {
nonce := s.getCurrentNonce(s.fundedAccEthAddr)

// Create series of 3 tx messages. Expecting nonce to be incremented by 3
creationTx := s.buildContractCreationTx(nonce)
firstTransferTx := s.buildContractCallTx(nonce+1, testContractAddress)
secondTransferTx := s.buildContractCallTx(nonce+2, testContractAddress)

// Create and broadcast SDK transaction
sdkTx := s.buildSDKTxWithEVMMessages(
creationTx,
firstTransferTx,
secondTransferTx,
)

// Broadcast transaction
rsp := s.broadcastSDKTx(sdkTx)
s.Assert().NotEqual(rsp.Code, 0)
s.Require().NoError(s.network.WaitForNextBlock())

// Expected nonce should be incremented by 3
currentNonce := s.getCurrentNonce(s.fundedAccEthAddr)
s.Assert().Equal(nonce+3, currentNonce)

// Assert all transactions included in block
for _, tx := range []gethcore.Transaction{creationTx, firstTransferTx, secondTransferTx} {
blockNum, blockHash := WaitForReceipt(s, tx.Hash())
s.Require().NotNil(blockNum)
s.Require().NotNil(blockHash)
}
}

// buildSDKTxWithEVMMessages creates an SDK transaction with EVM messages
func (s *BackendSuite) buildSDKTxWithEVMMessages(txs ...gethcore.Transaction) sdk.Tx {
msgs := make([]sdk.Msg, len(txs))
for i, tx := range txs {
msg := &evm.MsgEthereumTx{}
err := msg.FromEthereumTx(&tx)
s.Require().NoError(err)
msgs[i] = msg
}

option, err := codectypes.NewAnyWithValue(&evm.ExtensionOptionsEthereumTx{})
s.Require().NoError(err)

txBuilder, _ := s.backend.ClientCtx().TxConfig.NewTxBuilder().(authtx.ExtensionOptionsTxBuilder)
txBuilder.SetExtensionOptions(option)
err = txBuilder.SetMsgs(msgs...)
s.Require().NoError(err)

// Set fees for all messages
totalGas := uint64(0)
for _, tx := range txs {
totalGas += tx.Gas()
}
fees := sdk.NewCoins(sdk.NewCoin("unibi", sdkmath.NewIntFromUint64(totalGas)))
txBuilder.SetFeeAmount(fees)
txBuilder.SetGasLimit(totalGas)

return txBuilder.GetTx()
}
36 changes: 32 additions & 4 deletions token-registry/assetlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func NibiruAssetList() AssetList {
func TOKENS() []Token {
return []Token{
{
Name: "Nibiru",
Description: "The native token of Nibiru blockchain",
ExtendedDescription: some("Nibiru is a smart contract ecosystem with a high-performance, EVM-equivalent execution layer. Nibiru is engineered to meet the growing demand for versatile, scalable, and easy-to-use Web3 applications."),
Socials: &SocialLinks{
Expand All @@ -28,7 +29,6 @@ func TOKENS() []Token {
{Denom: "attonibi", Exponent: 18},
},
Base: "unibi",
Name: "Nibiru",
Display: "nibi",
Symbol: "NIBI",
LogoURIs: &LogoURIs{
Expand All @@ -48,6 +48,7 @@ func TOKENS() []Token {
TypeAsset: TypeAsset_SDKCoin,
},
{
Name: "Liquid Staked Nibiru (Eris)",
Description: "Liquid Staked Nibiru (Eris)",
ExtendedDescription: some("Liquid Staked Nibiru, powered by Eris Protocol's amplifier contracts. Nibiru is a smart contract ecosystem with a high-performance, EVM-equivalent execution layer. Nibiru is engineered to meet the growing demand for versatile, scalable, and easy-to-use Web3 applications."),
Socials: &SocialLinks{
Expand All @@ -59,7 +60,6 @@ func TOKENS() []Token {
{Denom: "stNIBI", Exponent: 6},
},
Base: "tf/nibi1udqqx30cw8nwjxtl4l28ym9hhrp933zlq8dqxfjzcdhvl8y24zcqpzmh8m/ampNIBI",
Name: "Liquid Staked Nibiru (Eris)",
Display: "stNIBI",
Symbol: "stNIBI",
LogoURIs: &LogoURIs{
Expand Down Expand Up @@ -88,13 +88,13 @@ func TOKENS() []Token {
TypeAsset: TypeAsset_SDKCoin,
},
{
Name: "Noble USDC",
Description: "Noble USDC on Nibiru",
DenomUnits: []DenomUnit{
{Denom: "ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349", Exponent: 0},
{Denom: "usdc", Exponent: 6},
},
Base: "ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349",
Name: "Noble USDC",
Display: "usdc",
Symbol: "USDC",
Traces: []Trace{
Expand Down Expand Up @@ -131,7 +131,9 @@ func TOKENS() []Token {
},
TypeAsset: TypeAsset_ICS20,
},

{
Name: "Astrovault token",
Description: "AXV",
ExtendedDescription: some("AXV is the Astrovault token."),
Socials: &SocialLinks{
Expand All @@ -143,7 +145,6 @@ func TOKENS() []Token {
{Denom: "AXV", Exponent: 6},
},
Base: "tf/nibi1vetfuua65frvf6f458xgtjerf0ra7wwjykrdpuyn0jur5x07awxsfka0ga/axv",
Name: "AXV",
Display: "AXV",
Symbol: "AXV",
LogoURIs: &LogoURIs{
Expand All @@ -162,6 +163,33 @@ func TOKENS() []Token {
},
TypeAsset: TypeAsset_SDKCoin,
},

{
Name: "Astrovault Nibiru LST (xNIBI)",
Description: "Astrovault Nibiru LST (xNIBI)",
TypeAsset: TypeAsset_CW20,
ExtendedDescription: some("xNIBI is a liquid staking derivative for NIBI created by Astrovault."),
Socials: &SocialLinks{
Website: some("https://astrovault.io/"),
Twitter: some("https://x.com/axvdex"),
},
DenomUnits: []DenomUnit{
{Denom: "cw20:nibi1cehpv50vl90g9qkwwny8mw7txw79zs6f7wsfe8ey7dgp238gpy4qhdqjhm", Exponent: 0},
{Denom: "xNIBI", Exponent: 6},
},
Base: "cw20:nibi1cehpv50vl90g9qkwwny8mw7txw79zs6f7wsfe8ey7dgp238gpy4qhdqjhm",
Display: "xNIBI",
Symbol: "xNIBI",
LogoURIs: &LogoURIs{
Svg: some("./img/0004_astrovault-xnibi.svg"),
},
Images: []AssetImage{
{
Svg: some("./img/0004_astrovault-xnibi.svg"),
},
},
},

{
Description: "uoprek",
DenomUnits: []DenomUnit{
Expand Down
19 changes: 19 additions & 0 deletions token-registry/img/0004_astrovault-xnibi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion token-registry/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ type ImageSync struct {
}

// TypeAsset is an enum type for "type_asset". Valid values include "sdk.coin",
// "ics20", and "erc20".
// "ics20", and "erc20". See [Examples].
//
// [Examples]: https://www.notion.so/nibiru/Nibiru-Token-Registry-Info-Fungible-Tokens-on-Nibiru-cf46d37ccd9c4c33bb083e20e0fa8e20?pvs=4
type TypeAsset string

const (
TypeAsset_SDKCoin TypeAsset = "sdk.coin"
TypeAsset_ICS20 TypeAsset = "ics20"
TypeAsset_ERC20 TypeAsset = "erc20"
TypeAsset_CW20 TypeAsset = "cw20"
)

// Trace represents trace data for cross-chain or liquid staking assets.
Expand Down
6 changes: 4 additions & 2 deletions x/evm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ const (
CallTypeSmart
)

var EVM_MODULE_ADDRESS gethcommon.Address
var EVM_MODULE_ADDRESS_NIBI sdk.AccAddress
var (
EVM_MODULE_ADDRESS gethcommon.Address
EVM_MODULE_ADDRESS_NIBI sdk.AccAddress
)

func init() {
EVM_MODULE_ADDRESS_NIBI = authtypes.NewModuleAddress(ModuleName)
Expand Down
Loading

0 comments on commit 1eb06dd

Please sign in to comment.