From 6267f425c13b08a168896c7a659bd14ae82d1b24 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Wed, 19 Feb 2025 15:58:45 +0000 Subject: [PATCH] Do not return remaining gas --- nativeasset/contract.go | 2 +- params/hooks_libevm.go | 9 +++------ precompile/contract/interfaces.go | 2 +- precompile/contract/mocks.go | 7 +++---- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/nativeasset/contract.go b/nativeasset/contract.go index e08e0d652e..523e55b33c 100644 --- a/nativeasset/contract.go +++ b/nativeasset/contract.go @@ -141,7 +141,7 @@ func (c *NativeAssetCall) Run(accessibleState contract.AccessibleState, caller c stateDB.SubBalanceMultiCoin(caller, assetID, assetAmount) stateDB.AddBalanceMultiCoin(to, assetID, assetAmount) - ret, remainingGas, err = accessibleState.Call(to, callData, remainingGas, new(uint256.Int), vm.WithUNSAFECallerAddressProxying()) + ret, err = accessibleState.Call(to, callData, remainingGas, new(uint256.Int), vm.WithUNSAFECallerAddressProxying()) // When an error was returned by the EVM or when setting the creation code // above we revert to the snapshot and consume any gas remaining. Additionally diff --git a/params/hooks_libevm.go b/params/hooks_libevm.go index 58dcc0316f..ccec38705c 100644 --- a/params/hooks_libevm.go +++ b/params/hooks_libevm.go @@ -172,17 +172,14 @@ func (a accessableState) GetSnowContext() *snow.Context { return GetExtra(a.env.ChainConfig()).SnowCtx } -func (a accessableState) Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) (ret []byte, gasRemaining uint64, err error) { +func (a accessableState) Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) (ret []byte, err error) { start := a.env.Gas() ret, err = a.env.Call(addr, input, gas, value, opts...) used := start - a.env.Gas() if used > gas { - return ret, 0, vm.ErrOutOfGas + return ret, vm.ErrOutOfGas } - // `gasRemaining` is `gas` because [vm.PrecompileEnvironment]'s `Call` method - // should consume the gas from the environment directly - gasRemaining = gas - return ret, gasRemaining, err + return ret, err } type precompileBlockContext struct { diff --git a/precompile/contract/interfaces.go b/precompile/contract/interfaces.go index 7de1423a02..a1ae9d5682 100644 --- a/precompile/contract/interfaces.go +++ b/precompile/contract/interfaces.go @@ -61,7 +61,7 @@ type AccessibleState interface { GetBlockContext() BlockContext GetSnowContext() *snow.Context GetChainConfig() precompileconfig.ChainConfig - Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) (ret []byte, gasRemaining uint64, _ error) + Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) (ret []byte, _ error) } // ConfigurationBlockContext defines the interface required to configure a precompile. diff --git a/precompile/contract/mocks.go b/precompile/contract/mocks.go index 6a83011623..6da91cc237 100644 --- a/precompile/contract/mocks.go +++ b/precompile/contract/mocks.go @@ -306,7 +306,7 @@ func (m *MockAccessibleState) EXPECT() *MockAccessibleStateMockRecorder { } // Call mocks base method. -func (m *MockAccessibleState) Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) ([]byte, uint64, error) { +func (m *MockAccessibleState) Call(addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...vm.CallOption) ([]byte, error) { m.ctrl.T.Helper() varargs := []any{addr, input, gas, value} for _, a := range opts { @@ -314,9 +314,8 @@ func (m *MockAccessibleState) Call(addr common.Address, input []byte, gas uint64 } ret := m.ctrl.Call(m, "Call", varargs...) ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(uint64) - ret2, _ := ret[2].(error) - return ret0, ret1, ret2 + ret1, _ := ret[1].(error) + return ret0, ret1 } // Call indicates an expected call of Call.