Skip to content

feat: x/precisebank module #69

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

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
3633be5
feat: x/precisebank module
dudong2 Apr 13, 2025
8557624
test: fix unit tests
dudong2 Apr 14, 2025
3ca1382
test: fix markdown lint
dudong2 Apr 14, 2025
2d9ef26
test: apply gci for x/precisebank
dudong2 Apr 14, 2025
1d51900
test: fix markdown lint
dudong2 Apr 14, 2025
fb186ed
test: fix lint
dudong2 Apr 14, 2025
5083839
feat: generalize decimals
dudong2 Apr 14, 2025
c4622ce
feat: add query cli
dudong2 Apr 14, 2025
fefeade
feat: generalize conversion factor
dudong2 Apr 15, 2025
5fc56eb
feat: add invariant about total supply
dudong2 Apr 15, 2025
0dd0703
chore: move config related files to evmd/config
dudong2 Apr 17, 2025
7982397
feat: store coin info (denom, conversion factor)
dudong2 Apr 17, 2025
67f023b
chore: remove chain specific logic from x/vm/keeper/keeper.go
dudong2 Apr 17, 2025
e4924a3
test: fix lint
dudong2 Apr 17, 2025
ba99fdb
chore: revert go.mod
dudong2 Apr 17, 2025
25ad411
test: add fuzz test
dudong2 Apr 17, 2025
2f02e25
test: fix fuzz test
dudong2 Apr 17, 2025
fc0898b
test: fix test_find_solidity_files
dudong2 Apr 17, 2025
9d27934
test: fix lint for python file
dudong2 Apr 17, 2025
1a00eec
feat: use precisebank module from precompile
dudong2 Apr 19, 2025
a0f13ce
Revert "feat: store coin info (denom, conversion factor)"
dudong2 Apr 19, 2025
8933a29
chore: add ConversionFactorVal for genesis block
dudong2 Apr 19, 2025
065f9b9
chore: remove unused proto import
dudong2 Apr 19, 2025
1d98d07
test: add generalized decimal tests
dudong2 Apr 21, 2025
7fd6c3f
test: add random value test with multi decimals
dudong2 Apr 22, 2025
028ba44
test: add contract interaction test
dudong2 Apr 22, 2025
acf3eb5
feat: remove flooring logic
dudong2 Apr 23, 2025
811a972
Revert "feat: remove flooring logic"
dudong2 Apr 24, 2025
71bfd83
feat: change logic from flooring to precisebank
dudong2 Apr 24, 2025
ef4a631
Revert "chore: move config related files to evmd/config"
dudong2 Apr 24, 2025
226b3ba
fix: node start
dudong2 Apr 25, 2025
52d7a1b
refactor: bank wrapper in x/vm scaling codes
dudong2 Apr 25, 2025
2d4a8cf
test: fix lint
dudong2 Apr 25, 2025
f0308f8
chore: cache EVMCoin infos before ResetTestConfig
dudong2 Apr 26, 2025
d5b5451
fix: return from sendExtendedCoins, if from == to
dudong2 Apr 26, 2025
55cf3f7
test: add SEED for deterministic random test
dudong2 Apr 26, 2025
ea4e94e
test: add random evm coin transfer with random gas
dudong2 Apr 26, 2025
73eb1c6
test: fix lint
dudong2 Apr 26, 2025
82aef4e
test: revert TestEvmAnteTestSuite test cases
dudong2 Apr 26, 2025
17fc32e
chore: revert useless changes
dudong2 Apr 26, 2025
e4dc90b
chore: remove evmtype constant dependency from precisebank module
dudong2 Apr 26, 2025
509fcd1
chore: register precisebank query cli to AppModuleBasic
dudong2 Apr 26, 2025
1553be2
test: remove useless configurator setting
dudong2 Apr 26, 2025
5e03608
fix: build
dudong2 Apr 26, 2025
5c26eea
fix: lint
dudong2 Apr 26, 2025
cbcb22c
feat: add extended denom to 18 decimals
dudong2 Apr 27, 2025
5e29b30
refactor: ConversionFactorVal -> Decimals
dudong2 Apr 27, 2025
0339a91
chore: sdkmath -> math
dudong2 Apr 27, 2025
bc949fc
chore: revert useless changes
dudong2 Apr 27, 2025
df17bb3
chore: remove useless check for extended denom
dudong2 Apr 27, 2025
49d18f0
refactor: simplify GetBalance of BankWrapper
dudong2 Apr 27, 2025
c736fe3
test: restore removed test
dudong2 Apr 27, 2025
8b39553
chore: remove useless decimal validation check
dudong2 Apr 27, 2025
82eaea7
chore: fix condition more clearly
dudong2 Apr 27, 2025
22bd4ba
docs: CHANGELOG.md
dudong2 Apr 27, 2025
c9c6073
chore: use only precisebank module for evm module and precompile
dudong2 Apr 27, 2025
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
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,25 @@ jobs:
run: |
make test-scripts
if: env.GIT_DIFF

test-fuzz:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: "1.22"
check-latest: true
- uses: actions/checkout@v4
- uses: technote-space/[email protected]
with:
PATTERNS: |
.github/workflows/test.yml
**/**.sol
**/**.go
go.mod
go.sum
*.toml
- name: run fuzz tests
run: |
make test-fuzz
if: env.GIT_DIFF
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

### FEATURES

- [\#69](https://github.com/cosmos/evm/pull/69) Add new `x/precisebank` module with bank decimal extension for EVM usage.

### STATE BREAKING

- Refactored evmos/os into cosmos/evm
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ else
go test -tags=test -mod=readonly $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES)
endif

# Use the old Apple linker to workaround broken xcode - https://github.com/golang/go/issues/65169
ifeq ($(OS_FAMILY),Darwin)
FUZZLDFLAGS := -ldflags=-extldflags=-Wl,-ld_classic
endif

test-fuzz:
go test -tags=test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz=FuzzMintCoins ./x/precisebank/keeper
go test -tags=test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz=FuzzBurnCoins ./x/precisebank/keeper
go test -tags=test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz=FuzzSendCoins ./x/precisebank/keeper
go test -tags=test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz=FuzzGenesisStateValidate_NonZeroRemainder ./x/precisebank/types
go test -tags=test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz=FuzzGenesisStateValidate_ZeroRemainder ./x/precisebank/types

test-scripts:
@echo "Running scripts tests"
@pytest -s -vv ./scripts
Expand Down
8 changes: 3 additions & 5 deletions ante/evm/04_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,9 @@ func CheckTxFee(txFeeInfo *tx.Fee, txFee *big.Int, txGasLimit uint64) error {
return nil
}

convertedAmount := sdkmath.NewIntFromBigInt(evmtypes.ConvertAmountFrom18DecimalsBigInt(txFee))

baseDenom := evmtypes.GetEVMCoinDenom()
if !txFeeInfo.Amount.AmountOf(baseDenom).Equal(convertedAmount) {
return errorsmod.Wrapf(errortypes.ErrInvalidRequest, "invalid AuthInfo Fee Amount (%s != %s)", txFeeInfo.Amount, convertedAmount)
evmExtendedDenom := evmtypes.GetEVMCoinExtendedDenom()
if !txFeeInfo.Amount.AmountOf(evmExtendedDenom).Equal(sdkmath.NewIntFromBigInt(txFee)) {
return errorsmod.Wrapf(errortypes.ErrInvalidRequest, "invalid AuthInfo Fee Amount (%s != %s)", txFeeInfo.Amount, txFee)
}

if txFeeInfo.GasLimit != txGasLimit {
Expand Down
16 changes: 7 additions & 9 deletions ante/evm/04_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,25 +245,23 @@ func (suite *EvmAnteTestSuite) TestCheckTxFee() {
},
}

for _, decimals := range []evmtypes.Decimals{
evmtypes.SixDecimals,
evmtypes.EighteenDecimals,
for _, chainID := range []string{
testconstants.ExampleChainID,
testconstants.SixDecimalsChainID,
} {
for _, tc := range testCases {
suite.Run(fmt.Sprintf("%d decimals, %s", decimals, tc.name), func() {
suite.Run(fmt.Sprintf("%s, %s", chainID, tc.name), func() {
// Call the configurator to set the EVM coin required for the
// function to be tested.
configurator := evmtypes.NewEVMConfigurator()
configurator.ResetTestConfig()
suite.Require().NoError(configurator.WithEVMCoinInfo(testconstants.ExampleAttoDenom, uint8(decimals)).Configure())
suite.Require().NoError(configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[chainID]).Configure())

// If decimals is not 18 decimals, we have to convert txFeeInfo to original
// decimals representation.
originalAmount := amount
evmCoinDecimal := evmtypes.GetEVMCoinDecimals()
originalAmount = originalAmount.Quo(evmCoinDecimal.ConversionFactor())
evmExtendedDenom := evmtypes.GetEVMCoinExtendedDenom()

coins := sdktypes.Coins{sdktypes.Coin{Denom: "aatom", Amount: originalAmount}}
coins := sdktypes.Coins{sdktypes.Coin{Denom: evmExtendedDenom, Amount: amount}}

// This struct should hold values in the original representation
txFeeInfo := &tx.Fee{
Expand Down
12 changes: 9 additions & 3 deletions ante/testutils/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,19 @@ func (suite *AnteTestSuite) SetupTest() {
// get the denom and decimals set when initialized the chain
// to set them again
// when resetting the chain config
denom := evmtypes.GetEVMCoinDenom() //nolint:staticcheck
decimals := evmtypes.GetEVMCoinDecimals() //nolint:staticcheck
denom := evmtypes.GetEVMCoinDenom() //nolint:staticcheck
extendedDenom := evmtypes.GetEVMCoinExtendedDenom() //nolint:staticcheck
decimals := evmtypes.GetEVMCoinDecimals() //nolint:staticcheck

configurator := evmtypes.NewEVMConfigurator()
configurator.ResetTestConfig()
err := configurator.
WithChainConfig(chainConfig).
WithEVMCoinInfo(denom, uint8(decimals)).
WithEVMCoinInfo(evmtypes.EvmCoinInfo{
Denom: denom,
ExtendedDenom: extendedDenom,
Decimals: decimals,
}).
Configure()
suite.Require().NoError(err)

Expand Down
Loading
Loading