From 3a6d15f06ef68fe1fabeff8c62833486a818407c Mon Sep 17 00:00:00 2001 From: Antonio Pitasi Date: Wed, 30 Jul 2025 14:56:33 +0200 Subject: [PATCH] x/vm: remove MaxPrecompileCalls --- CHANGELOG.md | 2 ++ .../precompiles/staking/test_integration.go | 33 ------------------- x/vm/statedb/statedb.go | 8 ----- x/vm/types/call.go | 5 --- 4 files changed, 2 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6abdf0aec..62d645f48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ ### STATE BREAKING +- [\#381](https://github.com/cosmos/evm/pull/381) Remove MaxPrecompileCalls (was 7). A transaction can now make any number of precompiled contracts calls. + ### API-BREAKING - [\#477](https://github.com/cosmos/evm/pull/477) Refactor precompile constructors to accept keeper interfaces instead of concrete implementations, breaking the existing `NewPrecompile` function signatures. diff --git a/tests/integration/precompiles/staking/test_integration.go b/tests/integration/precompiles/staking/test_integration.go index 7d49f82df..7443f78b5 100644 --- a/tests/integration/precompiles/staking/test_integration.go +++ b/tests/integration/precompiles/staking/test_integration.go @@ -1813,39 +1813,6 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp Expect(txSenderFinalBal.Amount).To(Equal(txSenderInitialBal.Amount.Sub(fees))) }) - It("should revert the changes and NOT delegate - failed tx - max precompile calls reached", func() { - callArgs := testutiltypes.CallArgs{ - ContractABI: stakingReverterContract.ABI, - MethodName: "multipleDelegations", - Args: []interface{}{ - big.NewInt(int64(evmtypes.MaxPrecompileCalls + 2)), s.network.GetValidators()[0].OperatorAddress, - }, - } - - // Tx should fail due to MaxPrecompileCalls - _, _, err := s.factory.CallContractAndCheckLogs( - s.keyring.GetPrivKey(0), - evmtypes.EvmTxArgs{ - To: &stkReverterAddr, - GasPrice: gasPrice.BigInt(), - }, - callArgs, - execRevertedCheck, - ) - Expect(err).To(BeNil(), "error while calling the smart contract: %v", err) - - // contract balance should remain unchanged - balRes, err := s.grpcHandler.GetBalanceFromBank(stkReverterAddr.Bytes(), s.bondDenom) - Expect(err).To(BeNil()) - contractFinalBalance := balRes.Balance - Expect(contractFinalBalance.Amount).To(Equal(contractInitialBalance.Amount)) - - // No delegation should be created - _, err = s.grpcHandler.GetDelegation(sdk.AccAddress(stkReverterAddr.Bytes()).String(), s.network.GetValidators()[0].OperatorAddress) - Expect(err).NotTo(BeNil()) - Expect(err.Error()).To(ContainSubstring("not found"), "expected NO delegation created") - }) - It("should delegate before and after intentionaly ignored delegation revert - successful tx", func() { delegationAmount := math.NewInt(10) expectedDelegationAmount := delegationAmount.Add(delegationAmount) diff --git a/x/vm/statedb/statedb.go b/x/vm/statedb/statedb.go index d2f8ae571..e3da22466 100644 --- a/x/vm/statedb/statedb.go +++ b/x/vm/statedb/statedb.go @@ -20,7 +20,6 @@ import ( "github.com/cosmos/evm/x/vm/store/snapshotmulti" vmstoretypes "github.com/cosmos/evm/x/vm/store/types" - "github.com/cosmos/evm/x/vm/types" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" @@ -76,9 +75,6 @@ type StateDB struct { // Per-transaction access list accessList *accessList - - // The count of calls to precompiles - precompileCallsCounter uint8 } func (s *StateDB) CreateContract(address common.Address) { @@ -440,10 +436,6 @@ func (s *StateDB) AddPrecompileFn(addr common.Address, snapshot int, events sdk. return fmt.Errorf("could not add precompile call to address %s. State object not found", addr) } stateObject.AddPrecompileFn(snapshot, events) - s.precompileCallsCounter++ - if s.precompileCallsCounter > types.MaxPrecompileCalls { - return fmt.Errorf("max calls to precompiles (%d) reached", types.MaxPrecompileCalls) - } return nil } diff --git a/x/vm/types/call.go b/x/vm/types/call.go index 957084736..b3439d941 100644 --- a/x/vm/types/call.go +++ b/x/vm/types/call.go @@ -8,8 +8,3 @@ const ( // Internal call type is used in case of smart contract methods calls Internal ) - -// MaxPrecompileCalls is the maximum number of precompile -// calls within a transaction. We want to limit this because -// for each precompile tx we're creating a cached context -const MaxPrecompileCalls uint8 = 7